var prefService = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);

var Building_Effectiveness       = 100;
var Building_Max_Percentage      = 99 ;
var Building_Prov                = "";
var Building_Kingdom             = 0;
var Building_Island              = 0;
var Building_Race                = 0;
var Building_Personality         = 0;
var Building_Stance              = 0;
var Building_Available_Workers   = 0;
var Building_Total_Money         = 0;
var Building_Building_Cost       = 0;
var Building_Razing_Cost         = 0;
var Building_Total_Jobs          = 0;
var Building_Total_NW            = 0;
var Building_Total_Cost          = 0;


var Building_Available_Barren    = 0;
var Building_Available_Homes     = 0;
var Building_Available_Farms     = 0;
var Building_Available_Mills     = 0;
var Building_Available_Banks     = 0;
var Building_Available_TG        = 0;
var Building_Available_Armouries = 0;
var Building_Available_Barracks  = 0;
var Building_Available_Forts     = 0;
var Building_Available_GS        = 0;
var Building_Available_Hospitals = 0;
var Building_Available_Guilds    = 0;
var Building_Available_Towers    = 0;
var Building_Available_TD        = 0;
var Building_Available_WT        = 0;
var Building_Available_Libraries = 0;
var Building_Available_Schools   = 0;
var Building_Available_Stables   = 0;
var Building_Available_Dungeons  = 0;
var Building_Available_Total     = 0;


var Building_Percentage_Barren    = 0;
var Building_Percentage_Homes     = 0;
var Building_Percentage_Farms     = 0;
var Building_Percentage_Mills     = 0;
var Building_Percentage_Banks     = 0;
var Building_Percentage_TG        = 0;
var Building_Percentage_Armouries = 0;
var Building_Percentage_Barracks  = 0;
var Building_Percentage_Forts     = 0;
var Building_Percentage_GS        = 0;
var Building_Percentage_Hospitals = 0;
var Building_Percentage_Guilds    = 0;
var Building_Percentage_Towers    = 0;
var Building_Percentage_TD        = 0;
var Building_Percentage_WT        = 0;
var Building_Percentage_Libraries = 0;
var Building_Percentage_Schools   = 0;
var Building_Percentage_Stables   = 0;
var Building_Percentage_Dungeons  = 0;
var Building_Percentage_Total     = 0;


var Building_Progress_Barren    = 0;
var Building_Progress_Homes     = 0;
var Building_Progress_Farms     = 0;
var Building_Progress_Mills     = 0;
var Building_Progress_Banks     = 0;
var Building_Progress_TG        = 0;
var Building_Progress_Armouries = 0;
var Building_Progress_Barracks  = 0;
var Building_Progress_Forts     = 0;
var Building_Progress_GS        = 0;
var Building_Progress_Hospitals = 0;
var Building_Progress_Guilds    = 0;
var Building_Progress_Towers    = 0;
var Building_Progress_TD        = 0;
var Building_Progress_WT        = 0;
var Building_Progress_Libraries = 0;
var Building_Progress_Schools   = 0;
var Building_Progress_Stables   = 0;
var Building_Progress_Dungeons  = 0;
var Building_Progress_Total     = 0;


var Building_Goal_Barren    = 0;
var Building_Goal_Homes     = 0;
var Building_Goal_Farms     = 0;
var Building_Goal_Mills     = 0;
var Building_Goal_Banks     = 0;
var Building_Goal_TG        = 0;
var Building_Goal_Armouries = 0;
var Building_Goal_Barracks  = 0;
var Building_Goal_Forts     = 0;
var Building_Goal_GS        = 0;
var Building_Goal_Hospitals = 0;
var Building_Goal_Guilds    = 0;
var Building_Goal_Towers    = 0;
var Building_Goal_TD        = 0;
var Building_Goal_WT        = 0;
var Building_Goal_Libraries = 0;
var Building_Goal_Schools   = 0;
var Building_Goal_Stables   = 0;
var Building_Goal_Dungeons  = 0;
var Building_Goal_Total     = 0;


var Build_This_Barren    = 0;
var Build_This_Homes     = 0;
var Build_This_Farms     = 0;
var Build_This_Mills     = 0;
var Build_This_Banks     = 0;
var Build_This_TG        = 0;
var Build_This_Armouries = 0;
var Build_This_Barracks  = 0;
var Build_This_Forts     = 0;
var Build_This_GS        = 0;
var Build_This_Hospitals = 0;
var Build_This_Guilds    = 0;
var Build_This_Towers    = 0;
var Build_This_TD        = 0;
var Build_This_WT        = 0;
var Build_This_Libraries = 0;
var Build_This_Schools   = 0;
var Build_This_Stables   = 0;
var Build_This_Dungeons  = 0;
var Build_This_Total     = 0;


var Building_Barren    = 0;
var Building_Homes     = 0;
var Building_Farms     = 0;
var Building_Mills     = 0;
var Building_Banks     = 0;
var Building_TG        = 0;
var Building_Armouries = 0;
var Building_Barracks  = 0;
var Building_Forts     = 0;
var Building_GS        = 0;
var Building_Hospitals = 0;
var Building_Guilds    = 0;
var Building_Towers    = 0;
var Building_TD        = 0;
var Building_WT        = 0;
var Building_Libraries = 0;
var Building_Schools   = 0;
var Building_Stables   = 0;
var Building_Dungeons  = 0;
var Building_Total     = 0;


//////////////////////////
//  Flat Rate Building  //
//////////////////////////

var Building_Barren_Population              = 0;
var Building_Barren_Bushels                 = 0;
var Building_Horses_Hold                    = 0;
var Building_Bushels_Shepherd_Bonus         = 0;
var Building_Extra_Population               = 0;
var Building_Extra_Population_Bonus         = 0;
var Building_Bushels_Produced               = 0;
var Building_Bushels_Produced_Bonus         = 0;
var Building_Gold_Produced                  = 0;
var Building_Gold_Produced_Bonus            = 0;
var Building_Wizard_Produced                = 0;
var Building_Guilds_Bonus                   = 0;
var Building_Runes_Produced                 = 0;
var Building_Runes_Produced_Bonus           = 0;
var Building_Horses_Produced                = 0;
var Building_Horses_Produced_Bonus          = 0;
var Building_Maximum_Prisoners              = 0;
var Building_Maximum_Prisoners_Bonus        = 0;
var Building_Thieves_Dens_Bonus             = 0;
var Building_Banks_Bonus                    = 0;

//////////////////////////
//  Flat Rate Building  //
//////////////////////////


//////////////////////////
//  Percentage Building //
//////////////////////////

var Building_Birth_Rate                     = 0;
var Building_Birth_Rate_Bonus               = 0;
var Building_Construction_Cost              = 0;
var Building_Construction_Cost_Bonus        = 0;
var Building_Exploration_Cost               = 0;
var Building_Exploration_Cost_Bonus         = 0;
var Building_Increased_Income               = 0;
var Building_Increased_Income_Bonus         = 0;
var Building_Offensive_Military             = 0;
var Building_Offensive_Military_Bonus       = 0;
var Building_Training_Costs                 = 0;
var Building_Training_Costs_Bonus           = 0;
var Building_Daily_Wages                    = 0;
var Building_Daily_Wages_Bonus              = 0;
var Building_Draft_Costs                    = 0;
var Building_Draft_Costs_Bonus              = 0;
var Building_Attack_Time                    = 0;
var Building_Attack_Time_Bonus              = 0;
var Building_Defensive_Military             = 0;
var Building_Defensive_Military_Bonus       = 0;
var Building_Attacked_Losses                = 0;
var Building_Cure_Plague                    = 0;
var Building_Race_Hospitals_Bonus           = 0;
var Building_Military_Losses                = 0;
var Building_Military_Losses_Bonus          = 0;
var Building_Thievery_Losses                = 0;
var Building_Thievery_Losses_Bonus          = 0;
var Building_Thievery_Effectiveness         = 0;
var Building_Thievery_Effectiveness_Bonus   = 0;
var Building_Catching_Thieves               = 0;
var Building_Thievery_Damage                = 0;
var Building_Science_Effectiveness          = 0;
var Building_Science_Effectiveness_Bonus    = 0;
var Building_Science_Costs                  = 0;
var Building_Science_Costs_Bonus            = 0;
var Building_Books_Protected                = 0;
var Building_Books_Protected_Bonus          = 0;

//////////////////////////
//  Percentage Building //
//////////////////////////


function Task_Building() {


Building_Available_Barren    = document.getElementById('Building_Available_Barren').value;
Building_Available_Homes     = document.getElementById('Building_Available_Homes').value;
Building_Available_Farms     = document.getElementById('Building_Available_Farms').value;
Building_Available_Mills     = document.getElementById('Building_Available_Mills').value;
Building_Available_Banks     = document.getElementById('Building_Available_Banks').value;
Building_Available_TG        = document.getElementById('Building_Available_TG').value;
Building_Available_Armouries = document.getElementById('Building_Available_Armouries').value;
Building_Available_Barracks  = document.getElementById('Building_Available_Barracks').value;
Building_Available_Forts     = document.getElementById('Building_Available_Forts').value;
Building_Available_GS        = document.getElementById('Building_Available_GS').value;
Building_Available_Hospitals = document.getElementById('Building_Available_Hospitals').value;
Building_Available_Guilds    = document.getElementById('Building_Available_Guilds').value;
Building_Available_Towers    = document.getElementById('Building_Available_Towers').value;
Building_Available_TD        = document.getElementById('Building_Available_TD').value;
Building_Available_WT        = document.getElementById('Building_Available_WT').value;
Building_Available_Libraries = document.getElementById('Building_Available_Libraries').value;
Building_Available_Schools   = document.getElementById('Building_Available_Schools').value;
Building_Available_Stables   = document.getElementById('Building_Available_Stables').value;
Building_Available_Dungeons  = document.getElementById('Building_Available_Dungeons').value;

Building_Progress_Barren    = document.getElementById('Building_Progress_Barren').value;
Building_Progress_Homes     = document.getElementById('Building_Progress_Homes').value;
Building_Progress_Farms     = document.getElementById('Building_Progress_Farms').value;
Building_Progress_Mills     = document.getElementById('Building_Progress_Mills').value;
Building_Progress_Banks     = document.getElementById('Building_Progress_Banks').value;
Building_Progress_TG        = document.getElementById('Building_Progress_TG').value;
Building_Progress_Armouries = document.getElementById('Building_Progress_Armouries').value;
Building_Progress_Barracks  = document.getElementById('Building_Progress_Barracks').value;
Building_Progress_Forts     = document.getElementById('Building_Progress_Forts').value;
Building_Progress_GS        = document.getElementById('Building_Progress_GS').value;
Building_Progress_Hospitals = document.getElementById('Building_Progress_Hospitals').value;
Building_Progress_Guilds    = document.getElementById('Building_Progress_Guilds').value;
Building_Progress_Towers    = document.getElementById('Building_Progress_Towers').value;
Building_Progress_TD        = document.getElementById('Building_Progress_TD').value;
Building_Progress_WT        = document.getElementById('Building_Progress_WT').value;
Building_Progress_Libraries = document.getElementById('Building_Progress_Libraries').value;
Building_Progress_Schools   = document.getElementById('Building_Progress_Schools').value;
Building_Progress_Stables   = document.getElementById('Building_Progress_Stables').value;
Building_Progress_Dungeons  = document.getElementById('Building_Progress_Dungeons').value;

Building_Goal_Barren    = document.getElementById('Building_Goal_Barren').value;
Building_Goal_Homes     = document.getElementById('Building_Goal_Homes').value;
Building_Goal_Farms     = document.getElementById('Building_Goal_Farms').value;
Building_Goal_Mills     = document.getElementById('Building_Goal_Mills').value;
Building_Goal_Banks     = document.getElementById('Building_Goal_Banks').value;
Building_Goal_TG        = document.getElementById('Building_Goal_TG').value;
Building_Goal_Armouries = document.getElementById('Building_Goal_Armouries').value;
Building_Goal_Barracks  = document.getElementById('Building_Goal_Barracks').value;
Building_Goal_Forts     = document.getElementById('Building_Goal_Forts').value;
Building_Goal_GS        = document.getElementById('Building_Goal_GS').value;
Building_Goal_Hospitals = document.getElementById('Building_Goal_Hospitals').value;
Building_Goal_Guilds    = document.getElementById('Building_Goal_Guilds').value;
Building_Goal_Towers    = document.getElementById('Building_Goal_Towers').value;
Building_Goal_TD        = document.getElementById('Building_Goal_TD').value;
Building_Goal_WT        = document.getElementById('Building_Goal_WT').value;
Building_Goal_Libraries = document.getElementById('Building_Goal_Libraries').value;
Building_Goal_Schools   = document.getElementById('Building_Goal_Schools').value;
Building_Goal_Stables   = document.getElementById('Building_Goal_Stables').value;
Building_Goal_Dungeons  = document.getElementById('Building_Goal_Dungeons').value;



Building_Available_Barren    = Number( Building_Available_Barren );
Building_Available_Homes     = Number( Building_Available_Homes );
Building_Available_Farms     = Number( Building_Available_Farms );
Building_Available_Mills     = Number( Building_Available_Mills );
Building_Available_Banks     = Number( Building_Available_Banks );
Building_Available_TG        = Number( Building_Available_TG );
Building_Available_Armouries = Number( Building_Available_Armouries );
Building_Available_Barracks  = Number( Building_Available_Barracks );
Building_Available_Forts     = Number( Building_Available_Forts );
Building_Available_GS        = Number( Building_Available_GS );
Building_Available_Hospitals = Number( Building_Available_Hospitals );
Building_Available_Guilds    = Number( Building_Available_Guilds );
Building_Available_Towers    = Number( Building_Available_Towers );
Building_Available_TD        = Number( Building_Available_TD );
Building_Available_WT        = Number( Building_Available_WT );
Building_Available_Libraries = Number( Building_Available_Libraries );
Building_Available_Schools   = Number( Building_Available_Schools );
Building_Available_Stables   = Number( Building_Available_Stables );
Building_Available_Dungeons  = Number( Building_Available_Dungeons );

Building_Progress_Barren    = Number( Building_Progress_Barren );
Building_Progress_Homes     = Number( Building_Progress_Homes );
Building_Progress_Farms     = Number( Building_Progress_Farms );
Building_Progress_Mills     = Number( Building_Progress_Mills );
Building_Progress_Banks     = Number( Building_Progress_Banks );
Building_Progress_TG        = Number( Building_Progress_TG );
Building_Progress_Armouries = Number( Building_Progress_Armouries );
Building_Progress_Barracks  = Number( Building_Progress_Barracks );
Building_Progress_Forts     = Number( Building_Progress_Forts );
Building_Progress_GS        = Number( Building_Progress_GS );
Building_Progress_Hospitals = Number( Building_Progress_Hospitals );
Building_Progress_Guilds    = Number( Building_Progress_Guilds );
Building_Progress_Towers    = Number( Building_Progress_Towers );
Building_Progress_TD        = Number( Building_Progress_TD );
Building_Progress_WT        = Number( Building_Progress_WT );
Building_Progress_Libraries = Number( Building_Progress_Libraries );
Building_Progress_Schools   = Number( Building_Progress_Schools );
Building_Progress_Stables   = Number( Building_Progress_Stables );
Building_Progress_Dungeons  = Number( Building_Progress_Dungeons );

Building_Goal_Barren    = Number( Building_Goal_Barren );
Building_Goal_Homes     = Number( Building_Goal_Homes );
Building_Goal_Farms     = Number( Building_Goal_Farms );
Building_Goal_Mills     = Number( Building_Goal_Mills );
Building_Goal_Banks     = Number( Building_Goal_Banks );
Building_Goal_TG        = Number( Building_Goal_TG );
Building_Goal_Armouries = Number( Building_Goal_Armouries );
Building_Goal_Barracks  = Number( Building_Goal_Barracks );
Building_Goal_Forts     = Number( Building_Goal_Forts );
Building_Goal_GS        = Number( Building_Goal_GS );
Building_Goal_Hospitals = Number( Building_Goal_Hospitals );
Building_Goal_Guilds    = Number( Building_Goal_Guilds );
Building_Goal_Towers    = Number( Building_Goal_Towers );
Building_Goal_TD        = Number( Building_Goal_TD );
Building_Goal_WT        = Number( Building_Goal_WT );
Building_Goal_Libraries = Number( Building_Goal_Libraries );
Building_Goal_Schools   = Number( Building_Goal_Schools );
Building_Goal_Stables   = Number( Building_Goal_Stables );
Building_Goal_Dungeons  = Number( Building_Goal_Dungeons );



Building_Race        = document.getElementById('Building_Race').value;
Building_Personality = document.getElementById('Building_Personality').value;
Building_Stance      = document.getElementById('Building_Stance').value;


Building_Progress_Total = Building_Progress_Homes + Building_Progress_Farms + Building_Progress_Mills + Building_Progress_Banks + Building_Progress_TG + Building_Progress_Armouries + Building_Progress_Barracks + Building_Progress_Forts + Building_Progress_GS + Building_Progress_Hospitals + Building_Progress_Guilds + Building_Progress_Towers + Building_Progress_TD + Building_Progress_WT + Building_Progress_Libraries + Building_Progress_Schools + Building_Progress_Stables + Building_Progress_Dungeons;

Building_Available_Total = Building_Progress_Total + Building_Available_Barren + Building_Available_Homes + Building_Available_Farms + Building_Available_Mills + Building_Available_Banks + Building_Available_TG + Building_Available_Armouries + Building_Available_Barracks + Building_Available_Forts + Building_Available_GS + Building_Available_Hospitals + Building_Available_Guilds + Building_Available_Towers + Building_Available_TD + Building_Available_WT + Building_Available_Libraries + Building_Available_Schools + Building_Available_Stables + Building_Available_Dungeons ;

document.getElementById('Building_Available_Total').innerHTML = Building_Available_Total;


if ( Building_Available_Total > 0 ) {
document.getElementById('Building_Generate_Report').disabled = false ;
} else {
document.getElementById('Building_Generate_Report').disabled = true ;
}


if ( Building_Available_Total > 0 ) {

Building_Percentage_Barren    = Math.round( Building_Available_Barren    / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Homes     = Math.round( Building_Available_Homes     / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Farms     = Math.round( Building_Available_Farms     / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Mills     = Math.round( Building_Available_Mills     / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Banks     = Math.round( Building_Available_Banks     / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_TG        = Math.round( Building_Available_TG        / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Armouries = Math.round( Building_Available_Armouries / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Barracks  = Math.round( Building_Available_Barracks  / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Forts     = Math.round( Building_Available_Forts     / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_GS        = Math.round( Building_Available_GS        / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Hospitals = Math.round( Building_Available_Hospitals / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Guilds    = Math.round( Building_Available_Guilds    / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Towers    = Math.round( Building_Available_Towers    / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_TD        = Math.round( Building_Available_TD        / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_WT        = Math.round( Building_Available_WT        / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Libraries = Math.round( Building_Available_Libraries / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Schools   = Math.round( Building_Available_Schools   / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Stables   = Math.round( Building_Available_Stables   / Building_Available_Total * 1000 ) /10 ;
Building_Percentage_Dungeons  = Math.round( Building_Available_Dungeons  / Building_Available_Total * 1000 ) /10 ;

}

if ( Building_Available_Total == 0 ) {

Building_Percentage_Barren    = 0;
Building_Percentage_Homes     = 0;
Building_Percentage_Farms     = 0;
Building_Percentage_Mills     = 0;
Building_Percentage_Banks     = 0;
Building_Percentage_TG        = 0;
Building_Percentage_Armouries = 0;
Building_Percentage_Barracks  = 0;
Building_Percentage_Forts     = 0;
Building_Percentage_GS        = 0;
Building_Percentage_Hospitals = 0;
Building_Percentage_Guilds    = 0;
Building_Percentage_Towers    = 0;
Building_Percentage_TD        = 0;
Building_Percentage_WT        = 0;
Building_Percentage_Libraries = 0;
Building_Percentage_Schools   = 0;
Building_Percentage_Stables   = 0;
Building_Percentage_Dungeons  = 0;
Building_Percentage_Total     = 0;

}

document.getElementById('Building_Percentage_Barren').value    = Building_Percentage_Barren    ;
document.getElementById('Building_Percentage_Homes').value     = Building_Percentage_Homes     ;
document.getElementById('Building_Percentage_Farms').value     = Building_Percentage_Farms     ;
document.getElementById('Building_Percentage_Mills').value     = Building_Percentage_Mills     ;
document.getElementById('Building_Percentage_Banks').value     = Building_Percentage_Banks     ;
document.getElementById('Building_Percentage_TG').value        = Building_Percentage_TG        ;
document.getElementById('Building_Percentage_Armouries').value = Building_Percentage_Armouries ;
document.getElementById('Building_Percentage_Barracks').value  = Building_Percentage_Barracks  ;
document.getElementById('Building_Percentage_Forts').value     = Building_Percentage_Forts     ;
document.getElementById('Building_Percentage_GS').value        = Building_Percentage_GS        ;
document.getElementById('Building_Percentage_Hospitals').value = Building_Percentage_Hospitals ;
document.getElementById('Building_Percentage_Guilds').value    = Building_Percentage_Guilds    ;
document.getElementById('Building_Percentage_Towers').value    = Building_Percentage_Towers    ;
document.getElementById('Building_Percentage_TD').value        = Building_Percentage_TD        ;
document.getElementById('Building_Percentage_WT').value        = Building_Percentage_WT        ;
document.getElementById('Building_Percentage_Libraries').value = Building_Percentage_Libraries ;
document.getElementById('Building_Percentage_Schools').value   = Building_Percentage_Schools   ;
document.getElementById('Building_Percentage_Stables').value   = Building_Percentage_Stables   ;
document.getElementById('Building_Percentage_Dungeons').value  = Building_Percentage_Dungeons  ;




Building_Goal_Total = Building_Goal_Barren + Building_Goal_Homes + Building_Goal_Farms + Building_Goal_Mills + Building_Goal_Banks + Building_Goal_TG + Building_Goal_Armouries + Building_Goal_Barracks + Building_Goal_Forts + Building_Goal_GS + Building_Goal_Hospitals + Building_Goal_Guilds + Building_Goal_Towers + Building_Goal_TD + Building_Goal_WT + Building_Goal_Libraries + Building_Goal_Schools + Building_Goal_Stables + Building_Goal_Dungeons;


if (document.getElementById('Building_Percentage_Ratio').value=="Percentage") {

document.getElementById('Building_Goal_Total').innerHTML = Building_Goal_Total + "%";

if ( Building_Goal_Total != 100) { document.getElementById('Building_Goal_Total').style.color = "#880000";
} else { document.getElementById('Building_Goal_Total').style.color = "#000000"; }

Building_Goal_Total = 100;

} else {
document.getElementById('Building_Goal_Total').innerHTML = Building_Goal_Total;
document.getElementById('Building_Goal_Total').style.color = "#000000";
}



if ( Building_Goal_Total > 0 ) {

Build_This_Barren    = Math.round( Building_Goal_Barren    / Building_Goal_Total * Building_Available_Total - Building_Available_Barren    - Building_Progress_Barren    ) ;
Build_This_Homes     = Math.round( Building_Goal_Homes     / Building_Goal_Total * Building_Available_Total - Building_Available_Homes     - Building_Progress_Homes     ) ;
Build_This_Farms     = Math.round( Building_Goal_Farms     / Building_Goal_Total * Building_Available_Total - Building_Available_Farms     - Building_Progress_Farms     ) ;
Build_This_Mills     = Math.round( Building_Goal_Mills     / Building_Goal_Total * Building_Available_Total - Building_Available_Mills     - Building_Progress_Mills     ) ;
Build_This_Banks     = Math.round( Building_Goal_Banks     / Building_Goal_Total * Building_Available_Total - Building_Available_Banks     - Building_Progress_Banks     ) ;
Build_This_TG        = Math.round( Building_Goal_TG        / Building_Goal_Total * Building_Available_Total - Building_Available_TG        - Building_Progress_TG        ) ;
Build_This_Armouries = Math.round( Building_Goal_Armouries / Building_Goal_Total * Building_Available_Total - Building_Available_Armouries - Building_Progress_Armouries ) ;
Build_This_Barracks  = Math.round( Building_Goal_Barracks  / Building_Goal_Total * Building_Available_Total - Building_Available_Barracks  - Building_Progress_Barracks  ) ;
Build_This_Forts     = Math.round( Building_Goal_Forts     / Building_Goal_Total * Building_Available_Total - Building_Available_Forts     - Building_Progress_Forts     ) ;
Build_This_GS        = Math.round( Building_Goal_GS        / Building_Goal_Total * Building_Available_Total - Building_Available_GS        - Building_Progress_GS        ) ;
Build_This_Hospitals = Math.round( Building_Goal_Hospitals / Building_Goal_Total * Building_Available_Total - Building_Available_Hospitals - Building_Progress_Hospitals ) ;
Build_This_Guilds    = Math.round( Building_Goal_Guilds    / Building_Goal_Total * Building_Available_Total - Building_Available_Guilds    - Building_Progress_Guilds    ) ;
Build_This_Towers    = Math.round( Building_Goal_Towers    / Building_Goal_Total * Building_Available_Total - Building_Available_Towers    - Building_Progress_Towers    ) ;
Build_This_TD        = Math.round( Building_Goal_TD        / Building_Goal_Total * Building_Available_Total - Building_Available_TD        - Building_Progress_TD        ) ;
Build_This_WT        = Math.round( Building_Goal_WT        / Building_Goal_Total * Building_Available_Total - Building_Available_WT        - Building_Progress_WT        ) ;
Build_This_Libraries = Math.round( Building_Goal_Libraries / Building_Goal_Total * Building_Available_Total - Building_Available_Libraries - Building_Progress_Libraries ) ;
Build_This_Schools   = Math.round( Building_Goal_Schools   / Building_Goal_Total * Building_Available_Total - Building_Available_Schools   - Building_Progress_Schools   ) ;
Build_This_Stables   = Math.round( Building_Goal_Stables   / Building_Goal_Total * Building_Available_Total - Building_Available_Stables   - Building_Progress_Stables   ) ;
Build_This_Dungeons  = Math.round( Building_Goal_Dungeons  / Building_Goal_Total * Building_Available_Total - Building_Available_Dungeons  - Building_Progress_Dungeons  ) ;

}

if ( Building_Goal_Total == 0 ) {

Build_This_Barren    = 0;
Build_This_Homes     = 0;
Build_This_Farms     = 0;
Build_This_Mills     = 0;
Build_This_Banks     = 0;
Build_This_TG        = 0;
Build_This_Armouries = 0;
Build_This_Barracks  = 0;
Build_This_Forts     = 0;
Build_This_GS        = 0;
Build_This_Hospitals = 0;
Build_This_Guilds    = 0;
Build_This_Towers    = 0;
Build_This_TD        = 0;
Build_This_WT        = 0;
Build_This_Libraries = 0;
Build_This_Schools   = 0;
Build_This_Stables   = 0;
Build_This_Dungeons  = 0;

}

if ( Build_This_Barren    + Building_Available_Total == 0 ) Build_This_Barren    = 0;
if ( Build_This_Homes     + Building_Available_Total == 0 ) Build_This_Homes     = 0;
if ( Build_This_Farms     + Building_Available_Total == 0 ) Build_This_Farms     = 0;
if ( Build_This_Mills     + Building_Available_Total == 0 ) Build_This_Mills     = 0;
if ( Build_This_Banks     + Building_Available_Total == 0 ) Build_This_Banks     = 0;
if ( Build_This_TG        + Building_Available_Total == 0 ) Build_This_TG        = 0;
if ( Build_This_Armouries + Building_Available_Total == 0 ) Build_This_Armouries = 0;
if ( Build_This_Barracks  + Building_Available_Total == 0 ) Build_This_Barracks  = 0;
if ( Build_This_Forts     + Building_Available_Total == 0 ) Build_This_Forts     = 0;
if ( Build_This_GS        + Building_Available_Total == 0 ) Build_This_GS        = 0;
if ( Build_This_Hospitals + Building_Available_Total == 0 ) Build_This_Hospitals = 0;
if ( Build_This_Guilds    + Building_Available_Total == 0 ) Build_This_Guilds    = 0;
if ( Build_This_Towers    + Building_Available_Total == 0 ) Build_This_Towers    = 0;
if ( Build_This_TD        + Building_Available_Total == 0 ) Build_This_TD        = 0;
if ( Build_This_WT        + Building_Available_Total == 0 ) Build_This_WT        = 0;
if ( Build_This_Libraries + Building_Available_Total == 0 ) Build_This_Libraries = 0;
if ( Build_This_Schools   + Building_Available_Total == 0 ) Build_This_Schools   = 0;
if ( Build_This_Stables   + Building_Available_Total == 0 ) Build_This_Stables   = 0;
if ( Build_This_Dungeons  + Building_Available_Total == 0 ) Build_This_Dungeons  = 0;



document.getElementById('Build_This_Barren').value    = Build_This_Barren    ;
document.getElementById('Build_This_Homes').value     = Build_This_Homes     ;
document.getElementById('Build_This_Farms').value     = Build_This_Farms     ;
document.getElementById('Build_This_Mills').value     = Build_This_Mills     ;
document.getElementById('Build_This_Banks').value     = Build_This_Banks     ;
document.getElementById('Build_This_TG').value        = Build_This_TG        ;
document.getElementById('Build_This_Armouries').value = Build_This_Armouries ;
document.getElementById('Build_This_Barracks').value  = Build_This_Barracks  ;
document.getElementById('Build_This_Forts').value     = Build_This_Forts     ;
document.getElementById('Build_This_GS').value        = Build_This_GS        ;
document.getElementById('Build_This_Hospitals').value = Build_This_Hospitals ;
document.getElementById('Build_This_Guilds').value    = Build_This_Guilds    ;
document.getElementById('Build_This_Towers').value    = Build_This_Towers    ;
document.getElementById('Build_This_TD').value        = Build_This_TD        ;
document.getElementById('Build_This_WT').value        = Build_This_WT        ;
document.getElementById('Build_This_Libraries').value = Build_This_Libraries ;
document.getElementById('Build_This_Schools').value   = Build_This_Schools   ;
document.getElementById('Build_This_Stables').value   = Build_This_Stables   ;
document.getElementById('Build_This_Dungeons').value  = Build_This_Dungeons  ;



if ( Build_This_Barren    == 0 ) document.getElementById('Build_This_Barren').style.background    = "#000000";
if ( Build_This_Homes     == 0 ) document.getElementById('Build_This_Homes').style.background     = "#000000";
if ( Build_This_Farms     == 0 ) document.getElementById('Build_This_Farms').style.background     = "#000000";
if ( Build_This_Mills     == 0 ) document.getElementById('Build_This_Mills').style.background     = "#000000";
if ( Build_This_Banks     == 0 ) document.getElementById('Build_This_Banks').style.background     = "#000000";
if ( Build_This_TG        == 0 ) document.getElementById('Build_This_TG').style.background        = "#000000";
if ( Build_This_Armouries == 0 ) document.getElementById('Build_This_Armouries').style.background = "#000000";
if ( Build_This_Barracks  == 0 ) document.getElementById('Build_This_Barracks').style.background  = "#000000";
if ( Build_This_Forts     == 0 ) document.getElementById('Build_This_Forts').style.background     = "#000000";
if ( Build_This_GS        == 0 ) document.getElementById('Build_This_GS').style.background        = "#000000";
if ( Build_This_Hospitals == 0 ) document.getElementById('Build_This_Hospitals').style.background = "#000000";
if ( Build_This_Guilds    == 0 ) document.getElementById('Build_This_Guilds').style.background    = "#000000";
if ( Build_This_Towers    == 0 ) document.getElementById('Build_This_Towers').style.background    = "#000000";
if ( Build_This_TD        == 0 ) document.getElementById('Build_This_TD').style.background        = "#000000";
if ( Build_This_WT        == 0 ) document.getElementById('Build_This_WT').style.background        = "#000000";
if ( Build_This_Libraries == 0 ) document.getElementById('Build_This_Libraries').style.background = "#000000";
if ( Build_This_Schools   == 0 ) document.getElementById('Build_This_Schools').style.background   = "#000000";
if ( Build_This_Stables   == 0 ) document.getElementById('Build_This_Stables').style.background   = "#000000";
if ( Build_This_Dungeons  == 0 ) document.getElementById('Build_This_Dungeons').style.background  = "#000000";


if ( Build_This_Barren    > 0 ) document.getElementById('Build_This_Barren').style.background    = "#008800";
if ( Build_This_Homes     > 0 ) document.getElementById('Build_This_Homes').style.background     = "#008800";
if ( Build_This_Farms     > 0 ) document.getElementById('Build_This_Farms').style.background     = "#008800";
if ( Build_This_Mills     > 0 ) document.getElementById('Build_This_Mills').style.background     = "#008800";
if ( Build_This_Banks     > 0 ) document.getElementById('Build_This_Banks').style.background     = "#008800";
if ( Build_This_TG        > 0 ) document.getElementById('Build_This_TG').style.background        = "#008800";
if ( Build_This_Armouries > 0 ) document.getElementById('Build_This_Armouries').style.background = "#008800";
if ( Build_This_Barracks  > 0 ) document.getElementById('Build_This_Barracks').style.background  = "#008800";
if ( Build_This_Forts     > 0 ) document.getElementById('Build_This_Forts').style.background     = "#008800";
if ( Build_This_GS        > 0 ) document.getElementById('Build_This_GS').style.background        = "#008800";
if ( Build_This_Hospitals > 0 ) document.getElementById('Build_This_Hospitals').style.background = "#008800";
if ( Build_This_Guilds    > 0 ) document.getElementById('Build_This_Guilds').style.background    = "#008800";
if ( Build_This_Towers    > 0 ) document.getElementById('Build_This_Towers').style.background    = "#008800";
if ( Build_This_TD        > 0 ) document.getElementById('Build_This_TD').style.background        = "#008800";
if ( Build_This_WT        > 0 ) document.getElementById('Build_This_WT').style.background        = "#008800";
if ( Build_This_Libraries > 0 ) document.getElementById('Build_This_Libraries').style.background = "#008800";
if ( Build_This_Schools   > 0 ) document.getElementById('Build_This_Schools').style.background   = "#008800";
if ( Build_This_Stables   > 0 ) document.getElementById('Build_This_Stables').style.background   = "#008800";
if ( Build_This_Dungeons  > 0 ) document.getElementById('Build_This_Dungeons').style.background  = "#008800";


if ( Build_This_Barren    < 0 ) document.getElementById('Build_This_Barren').style.background    = "#880000";
if ( Build_This_Homes     < 0 ) document.getElementById('Build_This_Homes').style.background     = "#880000";
if ( Build_This_Farms     < 0 ) document.getElementById('Build_This_Farms').style.background     = "#880000";
if ( Build_This_Mills     < 0 ) document.getElementById('Build_This_Mills').style.background     = "#880000";
if ( Build_This_Banks     < 0 ) document.getElementById('Build_This_Banks').style.background     = "#880000";
if ( Build_This_TG        < 0 ) document.getElementById('Build_This_TG').style.background        = "#880000";
if ( Build_This_Armouries < 0 ) document.getElementById('Build_This_Armouries').style.background = "#880000";
if ( Build_This_Barracks  < 0 ) document.getElementById('Build_This_Barracks').style.background  = "#880000";
if ( Build_This_Forts     < 0 ) document.getElementById('Build_This_Forts').style.background     = "#880000";
if ( Build_This_GS        < 0 ) document.getElementById('Build_This_GS').style.background        = "#880000";
if ( Build_This_Hospitals < 0 ) document.getElementById('Build_This_Hospitals').style.background = "#880000";
if ( Build_This_Guilds    < 0 ) document.getElementById('Build_This_Guilds').style.background    = "#880000";
if ( Build_This_Towers    < 0 ) document.getElementById('Build_This_Towers').style.background    = "#880000";
if ( Build_This_TD        < 0 ) document.getElementById('Build_This_TD').style.background        = "#880000";
if ( Build_This_WT        < 0 ) document.getElementById('Build_This_WT').style.background        = "#880000";
if ( Build_This_Libraries < 0 ) document.getElementById('Build_This_Libraries').style.background = "#880000";
if ( Build_This_Schools   < 0 ) document.getElementById('Build_This_Schools').style.background   = "#880000";
if ( Build_This_Stables   < 0 ) document.getElementById('Build_This_Stables').style.background   = "#880000";
if ( Build_This_Dungeons  < 0 ) document.getElementById('Build_This_Dungeons').style.background  = "#880000";


Building_Barren    = Building_Available_Barren ;
Building_Homes     = Building_Available_Homes ;
Building_Farms     = Building_Available_Farms ;
Building_Mills     = Building_Available_Mills ;
Building_Banks     = Building_Available_Banks ;
Building_TG        = Building_Available_TG ;
Building_Armouries = Building_Available_Armouries ;
Building_Barracks  = Building_Available_Barracks ;
Building_Forts     = Building_Available_Forts ;
Building_GS        = Building_Available_GS ;
Building_Hospitals = Building_Available_Hospitals ;
Building_Guilds    = Building_Available_Guilds ;
Building_Towers    = Building_Available_Towers ;
Building_TD        = Building_Available_TD ;
Building_WT        = Building_Available_WT ;
Building_Libraries = Building_Available_Libraries ;
Building_Schools   = Building_Available_Schools ;
Building_Stables   = Building_Available_Stables ;
Building_Dungeons  = Building_Available_Dungeons ;


if ( document.getElementById('Building_Progress_Box').checked == true ) {

document.getElementById('Building_Goal_Box').disabled=false;
document.getElementById('Building_Goal_Box_Name').disabled=false;

Building_Barren    += Building_Progress_Barren ;
Building_Homes     += Building_Progress_Homes ;
Building_Farms     += Building_Progress_Farms ;
Building_Mills     += Building_Progress_Mills ;
Building_Banks     += Building_Progress_Banks ;
Building_TG        += Building_Progress_TG ;
Building_Armouries += Building_Progress_Armouries ;
Building_Barracks  += Building_Progress_Barracks ;
Building_Forts     += Building_Progress_Forts ;
Building_GS        += Building_Progress_GS ;
Building_Hospitals += Building_Progress_Hospitals ;
Building_Guilds    += Building_Progress_Guilds ;
Building_Towers    += Building_Progress_Towers ;
Building_TD        += Building_Progress_TD ;
Building_WT        += Building_Progress_WT ;
Building_Libraries += Building_Progress_Libraries ;
Building_Schools   += Building_Progress_Schools ;
Building_Stables   += Building_Progress_Stables ;
Building_Dungeons  += Building_Progress_Dungeons ;

} else {
document.getElementById('Building_Goal_Box').disabled=true;
document.getElementById('Building_Goal_Box_Name').disabled=true;
}

if ( document.getElementById('Building_Goal_Box').disabled == false ) {
if ( document.getElementById('Building_Goal_Box').checked == true ) {

Building_Barren    += Build_This_Barren ;
Building_Homes     += Build_This_Homes ;
Building_Farms     += Build_This_Farms ;
Building_Mills     += Build_This_Mills ;
Building_Banks     += Build_This_Banks ;
Building_TG        += Build_This_TG ;
Building_Armouries += Build_This_Armouries ;
Building_Barracks  += Build_This_Barracks ;
Building_Forts     += Build_This_Forts ;
Building_GS        += Build_This_GS ;
Building_Hospitals += Build_This_Hospitals ;
Building_Guilds    += Build_This_Guilds ;
Building_Towers    += Build_This_Towers ;
Building_TD        += Build_This_TD ;
Building_WT        += Build_This_WT ;
Building_Libraries += Build_This_Libraries ;
Building_Schools   += Build_This_Schools ;
Building_Stables   += Build_This_Stables ;
Building_Dungeons  += Build_This_Dungeons ;

}
}

Building_Effectiveness = document.getElementById('Building_Effectiveness').value;
Building_Effectiveness = Number( Building_Effectiveness );

if ( Building_Effectiveness <   0 ) document.getElementById('Building_Effectiveness').value = 0;
if ( Building_Effectiveness > 175 ) document.getElementById('Building_Effectiveness').value = 175;
if ( Building_Effectiveness <  50 ) Building_Effectiveness = 50;

Building_Building_Cost = Math.round( (Building_Available_Total + 11600) * 2/31 );
Building_Razing_Cost   = Math.round(  Building_Available_Total / 16 + 350      );

Building_Barren_Population            = 0; // ����� �����
Building_Barren_Bushels               = 0; // ����� �����

Building_Bushels_Shepherd_Bonus       = 0; // ����� �����
Building_Extra_Population_Bonus       = 1;
Building_Bushels_Produced_Bonus       = 1;
Building_Gold_Produced_Bonus          = 1;
Building_Construction_Cost_Bonus      = 1;
Building_Exploration_Cost_Bonus       = 1;
Building_Increased_Income_Bonus       = 1;
Building_Training_Costs_Bonus         = 1;
Building_Daily_Wages_Bonus            = 1;
Building_Draft_Costs_Bonus            = 1;
Building_Runes_Produced_Bonus         = 1;
Building_Horses_Produced_Bonus        = 1;
Building_Maximum_Prisoners_Bonus      = 1;
Building_Race_Hospitals_Bonus         = 1;
Building_Military_Losses_Bonus        = 1;
Building_Thievery_Losses_Bonus        = 1;
Building_Thievery_Effectiveness_Bonus = 1;
Building_Science_Effectiveness_Bonus  = 1;
Building_Science_Costs_Bonus          = 1;
Building_Birth_Rate_Bonus             = 1;
Building_Attack_Time_Bonus            = 1;
Building_Offensive_Military_Bonus     = 1;
Building_Defensive_Military_Bonus     = 1;
Building_Books_Protected_Bonus        = 1;

Building_Thieves_Dens_Bonus           = 1;
Building_Banks_Bonus                  = 1;
Building_Guilds_Bonus                 = 1;

// Bonuses

if ( document.getElementById('Building_Bonuses_Box').checked == true ) {

if ( document.getElementById('Building_War_Box').checked == true ) {
document.getElementById('Building_Stance').disabled = true;
document.getElementById('Building_Stance_Name').disabled = true;

if ( Building_Personality == 3 ) Building_Offensive_Military_Bonus = Building_Offensive_Military_Bonus * 1.15; // Warrior in war

Building_Attack_Time_Bonus     = Building_Attack_Time_Bonus     * 0.85;
Building_Military_Losses_Bonus = Building_Military_Losses_Bonus * 0.75;

} else {
document.getElementById('Building_Stance').disabled = false;
document.getElementById('Building_Stance_Name').disabled = false;


// if ( Building_Stance == 0 ) {}

if ( Building_Stance == 1 ) Building_Birth_Rate_Bonus = Building_Birth_Rate_Bonus * 2.0;

if ( Building_Stance == 2 ) {

// i didnt add the -50% gains factor to the GS in fort stance!

Building_Training_Costs_Bonus    = Building_Training_Costs_Bonus    * 0.75;
Building_Construction_Cost_Bonus = Building_Construction_Cost_Bonus * 0.85;
Building_Exploration_Cost_Bonus  = Building_Exploration_Cost_Bonus  * 2.00;

}

if ( Building_Stance == 3 ) {
Building_Attack_Time_Bonus = Building_Attack_Time_Bonus * 0.9;
Building_Daily_Wages_Bonus = Building_Daily_Wages_Bonus * 1.3;
}


}

document.getElementById('Building_Race_Name').innerHTML        = "Race";
document.getElementById('Building_Personality_Name').innerHTML = "Personality";

document.getElementById('Building_Race').disabled        = false;
document.getElementById('Building_Personality').disabled = false;

/*

0 = Human
1 = Elf
2 = Dwarf
3 = Orc
4 = Gnome - Removed
5 = Dark Elf - Removed
6 = Undead
7 = Avian
8 = Faery
9 = Halfling

*/

if ( Building_Race == 3 ) Building_Science_Effectiveness_Bonus  = Building_Science_Effectiveness_Bonus  * 0.80 ;

if ( Building_Race == 7 ) Building_Attack_Time_Bonus            = Building_Attack_Time_Bonus            * 0.70 ;
if ( Building_Race == 7 ) Building_Birth_Rate_Bonus             = Building_Birth_Rate_Bonus             * 1.50 ;

/*

0 = Merchant
1 = Mystic
2 = War Hero
3 = Warrior
4 = Rogue
5 = Shepherd - Removed
6 = Sage
7 = Cleric
8 = Artisan - Removed
9 = Freak - Removed
10 = General - Removed
11 = Tactician

*/

if ( Building_Personality == 0 ) Building_Increased_Income_Bonus       = Building_Increased_Income_Bonus       * 1    ; //(was removed)
if ( Building_Personality == 1 ) Building_Guilds_Bonus                 = Building_Guilds_Bonus                 * 2    ; // All Guilds are twice as effective
if ( Building_Personality == 1 ) Building_Runes_Produced_Bonus         = Building_Runes_Produced_Bonus         * 1    ; // All Towers are twice as effective (was removed in age 59)
if ( Building_Personality == 4 ) Building_Thieves_Dens_Bonus           = Building_Thieves_Dens_Bonus           * 2    ; // All TDs    are twice as effective (subject to DBE) (was removed in age 59)
if ( Building_Personality == 6 ) Building_Science_Effectiveness_Bonus  = Building_Science_Effectiveness_Bonus  * 1.33 ;
if ( Building_Personality == 6 ) Building_Books_Protected_Bonus        = Building_Books_Protected_Bonus        * 1    ; //(was removed)
if ( Building_Personality == 7 ) Building_Military_Losses_Bonus        = Building_Military_Losses_Bonus        * 0.3  ;
if ( Building_Personality == 11) Building_Attack_Time_Bonus            = Building_Attack_Time_Bonus            * 0.85 ;

} else {

// No bonuses

document.getElementById('Building_Stance_Name').disabled      = true;
document.getElementById('Building_Race_Name').disabled        = true;
document.getElementById('Building_Personality_Name').disabled = true;
document.getElementById('Building_Stance').disabled           = true;
document.getElementById('Building_Race').disabled             = true;
document.getElementById('Building_Personality').disabled      = true;

}

Building_Barren_Population = Building_Barren   * 15 ;
Building_Barren_Bushels    = Building_Barren   * 2  ;

Building_Extra_Population  = Building_Homes    * 10    * Building_Extra_Population_Bonus  ;
Building_Bushels_Produced  = Building_Farms    * 70   * Building_Bushels_Produced_Bonus * Building_Effectiveness / 100 + Building_Bushels_Shepherd_Bonus;
Building_Gold_Produced     = Building_Banks    * 25   * Building_Gold_Produced_Bonus    * Building_Effectiveness / 100 ;
Building_Wizard_Produced   = Building_Guilds   * 0.02 * Building_Guilds_Bonus           * Building_Effectiveness / 100 ;
Building_Runes_Produced    = Building_Towers   * 12   * Building_Runes_Produced_Bonus   * Building_Effectiveness / 100 ;
Building_Horses_Produced   = Building_Stables  * 2    * Building_Horses_Produced_Bonus  * Building_Effectiveness / 100 ;
Building_Horses_Hold       = Building_Stables  * 80   * Building_Horses_Produced_Bonus   ;
Building_Maximum_Prisoners = Building_Dungeons * 20   * Building_Maximum_Prisoners_Bonus ;

document.getElementById('Building_Barren_Population').innerHTML = Math.round( Building_Barren_Population        );
document.getElementById('Building_Barren_Bushels'   ).innerHTML = Math.round( Building_Barren_Bushels           );
document.getElementById('Building_Extra_Population' ).innerHTML = Math.round( Building_Extra_Population         );
document.getElementById('Building_Bushels_Produced' ).innerHTML = Math.round( Building_Bushels_Produced         );
document.getElementById('Building_Bushels_FL'       ).innerHTML = Math.round( Building_Bushels_Produced  * 1.25 );
document.getElementById('Building_Gold_Produced'    ).innerHTML = Math.round( Building_Gold_Produced            );
document.getElementById('Building_Wizard_Produced'  ).innerHTML = Math.round( Building_Wizard_Produced   * 100  ) /100;
document.getElementById('Building_Runes_Produced'   ).innerHTML = Math.round( Building_Runes_Produced           );
document.getElementById('Building_Horses_Produced'  ).innerHTML = Math.round( Building_Horses_Produced          );
document.getElementById('Building_Horses_Hold'      ).innerHTML = Math.round( Building_Horses_Hold              );
document.getElementById('Building_Maximum_Prisoners').innerHTML = Math.round( Building_Maximum_Prisoners        );
document.getElementById('Building_Prisoners_Offense').innerHTML = Math.round( Building_Maximum_Prisoners * 3    );
document.getElementById('Building_Prisoners_Produce').innerHTML = Math.round( Building_Maximum_Prisoners * 0.5  );
document.getElementById('Building_Prisoners_Jobs'   ).innerHTML = Math.round( Building_Maximum_Prisoners * 0.5  );

if ( 2*Building_Barren    > Building_Available_Total ) Building_Barren    = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Homes     > Building_Available_Total ) Building_Homes     = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Farms     > Building_Available_Total ) Building_Farms     = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Mills     > Building_Available_Total ) Building_Mills     = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Banks     > Building_Available_Total ) Building_Banks     = Math.round( Building_Available_Total / 2 );
if ( 2*Building_TG        > Building_Available_Total ) Building_TG        = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Armouries > Building_Available_Total ) Building_Armouries = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Barracks  > Building_Available_Total ) Building_Barracks  = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Forts     > Building_Available_Total ) Building_Forts     = Math.round( Building_Available_Total / 2 );
if ( 2*Building_GS        > Building_Available_Total ) Building_GS        = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Hospitals > Building_Available_Total ) Building_Hospitals = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Guilds    > Building_Available_Total ) Building_Guilds    = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Towers    > Building_Available_Total ) Building_Towers    = Math.round( Building_Available_Total / 2 );
if ( 2*Building_TD        > Building_Available_Total ) Building_TD        = Math.round( Building_Available_Total / 2 );
if ( 2*Building_WT        > Building_Available_Total ) Building_WT        = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Libraries > Building_Available_Total ) Building_Libraries = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Schools   > Building_Available_Total ) Building_Schools   = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Stables   > Building_Available_Total ) Building_Stables   = Math.round( Building_Available_Total / 2 );
if ( 2*Building_Dungeons  > Building_Available_Total ) Building_Dungeons  = Math.round( Building_Available_Total / 2 );


if ( Building_Available_Total == 0 ) {

Building_Birth_Rate             = 0;
Building_Construction_Cost      = 0;
Building_Exploration_Cost       = 0;
Building_Increased_Income       = 0;
Building_Offensive_Military     = 0;
Building_Training_Costs         = 0;
Building_Daily_Wages            = 0;
Building_Draft_Costs            = 0;
Building_Attack_Time            = 0;
Building_Defensive_Military     = 0;
Building_Attacked_Losses        = 0;
Building_Cure_Plague            = 0;
Building_Military_Losses        = 0;
Building_Thievery_Losses        = 0;
Building_Thievery_Effectiveness = 0;
Building_Catching_Thieves       = 0;
Building_Thievery_Damage        = 0;
Building_Science_Effectiveness  = 0;
Building_Science_Costs          = 0;
Building_Books_Protected        = 0;

} else {

Building_Birth_Rate             = Building_Modifier_Birth_Rate             * ( Building_Homes     / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Homes     / Building_Available_Total));
Building_Construction_Cost      = Building_Modifier_Construction_Cost      * ( Building_Mills     / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Mills     / Building_Available_Total));
Building_Exploration_Cost       = Building_Modifier_Exploration_Cost       * ( Building_Mills     / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Mills     / Building_Available_Total));
Building_Offensive_Military     = Building_Modifier_Offensive_Military     * ( Building_TG        / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_TG        / Building_Available_Total));
Building_Training_Costs         = Building_Modifier_Training_Costs         * ( Building_Armouries / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Armouries / Building_Available_Total));
Building_Daily_Wages            = Building_Modifier_Daily_Wages            * ( Building_Armouries / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Armouries / Building_Available_Total));
Building_Draft_Costs            = Building_Modifier_Draft_Costs            * ( Building_Armouries / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Armouries / Building_Available_Total));
Building_Attack_Time            = Building_Modifier_Attack_Time            * ( Building_Barracks  / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Barracks  / Building_Available_Total));
Building_Defensive_Military     = Building_Modifier_Defensive_Military     * ( Building_Forts     / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Forts     / Building_Available_Total));
Building_Attacked_Losses        = Building_Modifier_Attacked_Losses        * ( Building_GS        / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_GS        / Building_Available_Total));
Building_Cure_Plague            = Building_Modifier_Cure_Plague            * ( Building_Hospitals / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Hospitals / Building_Available_Total));
Building_Military_Losses        = Building_Modifier_Military_Losses        * ( Building_Hospitals / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Hospitals / Building_Available_Total));
Building_Catching_Thieves       = Building_Modifier_Catching_Thieves       * ( Building_WT        / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_WT        / Building_Available_Total));
Building_Thievery_Damage        = Building_Modifier_Thievery_Damage        * ( Building_WT        / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_WT        / Building_Available_Total));
Building_Science_Effectiveness  = Building_Modifier_Science_Bonus          * ( Building_Libraries / Building_Available_Total) * 100                    * (1 - ( Building_Libraries / Building_Available_Total));
Building_Science_Costs          = Building_Modifier_Science_Costs          * ( Building_Schools   / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Schools   / Building_Available_Total));
Building_Books_Protected        = Building_Modifier_Books_Protected        * ( Building_Schools   / Building_Available_Total) * Building_Effectiveness * (1 - ( Building_Schools   / Building_Available_Total));

//*** DBE ***//

Building_Increased_Income       = Building_Modifier_Increased_Income       * ( Building_Banks     / Building_Available_Total) * Building_Banks_Bonus        * Building_Effectiveness * (1 - ( Building_Banks / Building_Available_Total) * Building_Banks_Bonus        );
Building_Thievery_Losses        = Building_Modifier_Thievery_Losses        * ( Building_TD        / Building_Available_Total) * Building_Thieves_Dens_Bonus * Building_Effectiveness * (1 - ( Building_TD    / Building_Available_Total) * Building_Thieves_Dens_Bonus );
Building_Thievery_Effectiveness = Building_Modifier_Thievery_Effectiveness * ( Building_TD        / Building_Available_Total) * Building_Thieves_Dens_Bonus * Building_Effectiveness * (1 - ( Building_TD    / Building_Available_Total) * Building_Thieves_Dens_Bonus );

}


if ( Building_Birth_Rate             > Building_Modifier_Birth_Rate             * 25 ) Building_Birth_Rate             = Building_Modifier_Birth_Rate             * 25 ; // 99
if ( Building_Construction_Cost      > Building_Modifier_Construction_Cost      * 25 ) Building_Construction_Cost      = Building_Modifier_Construction_Cost      * 25 ; // 99
if ( Building_Exploration_Cost       > Building_Modifier_Exploration_Cost       * 25 ) Building_Exploration_Cost       = Building_Modifier_Exploration_Cost       * 25 ;
if ( Building_Increased_Income       > Building_Modifier_Increased_Income       * 25 ) Building_Increased_Income       = Building_Modifier_Increased_Income       * 25 ;
if ( Building_Offensive_Military     > Building_Modifier_Offensive_Military     * 25 ) Building_Offensive_Military     = Building_Modifier_Offensive_Military     * 25 ;
if ( Building_Training_Costs         > Building_Modifier_Training_Costs         * 25 ) Building_Training_Costs         = Building_Modifier_Training_Costs         * 25 ;
if ( Building_Daily_Wages            > Building_Modifier_Daily_Wages            * 25 ) Building_Daily_Wages            = Building_Modifier_Daily_Wages            * 25 ;
if ( Building_Draft_Costs            > Building_Modifier_Draft_Costs            * 25 ) Building_Draft_Costs            = Building_Modifier_Draft_Costs            * 25 ;
if ( Building_Attack_Time            > Building_Modifier_Attack_Time            * 25 ) Building_Attack_Time            = Building_Modifier_Attack_Time            * 25 ;
if ( Building_Defensive_Military     > Building_Modifier_Defensive_Military     * 25 ) Building_Defensive_Military     = Building_Modifier_Defensive_Military     * 25 ;
if ( Building_Attacked_Losses        > Building_Modifier_Attacked_Losses        * 25 ) Building_Attacked_Losses        = Building_Modifier_Attacked_Losses        * 25 ;
if ( Building_Cure_Plague            > Building_Modifier_Cure_Plague            * 25 ) Building_Cure_Plague            = Building_Modifier_Cure_Plague            * 25 ;
if ( Building_Military_Losses        > Building_Modifier_Military_Losses        * 25 ) Building_Military_Losses        = Building_Modifier_Military_Losses        * 25 ;
if ( Building_Thievery_Losses        > Building_Modifier_Thievery_Losses        * 25 ) Building_Thievery_Losses        = Building_Modifier_Thievery_Losses        * 25 ; // 99
if ( Building_Thievery_Effectiveness > Building_Modifier_Thievery_Effectiveness * 25 ) Building_Thievery_Effectiveness = Building_Modifier_Thievery_Effectiveness * 25 ;
if ( Building_Catching_Thieves       > Building_Modifier_Catching_Thieves       * 25 ) Building_Catching_Thieves       = Building_Modifier_Catching_Thieves       * 25 ;
if ( Building_Thievery_Damage        > Building_Modifier_Thievery_Damage        * 25 ) Building_Thievery_Damage        = Building_Modifier_Thievery_Damage        * 25 ;
if ( Building_Science_Effectiveness  > Building_Modifier_Science_Bonus          * 25 ) Building_Science_Effectiveness  = Building_Modifier_Science_Bonus          * 25 ;
if ( Building_Science_Costs          > Building_Modifier_Science_Costs          * 25 ) Building_Science_Costs          = Building_Modifier_Science_Costs          * 25 ;
if ( Building_Books_Protected        > Building_Modifier_Books_Protected        * 25 ) Building_Books_Protected        = Building_Modifier_Books_Protected        * 25 ;


if ( Building_Birth_Rate             > Building_Max_Percentage ) Building_Birth_Rate             = Building_Max_Percentage ;
if ( Building_Construction_Cost      > Building_Max_Percentage ) Building_Construction_Cost      = Building_Max_Percentage ;
if ( Building_Exploration_Cost       > Building_Max_Percentage ) Building_Exploration_Cost       = Building_Max_Percentage ;
if ( Building_Increased_Income       > Building_Max_Percentage ) Building_Increased_Income       = Building_Max_Percentage ;
if ( Building_Offensive_Military     > Building_Max_Percentage ) Building_Offensive_Military     = Building_Max_Percentage ;
if ( Building_Training_Costs         > Building_Max_Percentage ) Building_Training_Costs         = Building_Max_Percentage ;
if ( Building_Daily_Wages            > Building_Max_Percentage ) Building_Daily_Wages            = Building_Max_Percentage ;
if ( Building_Draft_Costs            > Building_Max_Percentage ) Building_Draft_Costs            = Building_Max_Percentage ;
if ( Building_Attack_Time            > Building_Max_Percentage ) Building_Attack_Time            = Building_Max_Percentage ;
if ( Building_Defensive_Military     > Building_Max_Percentage ) Building_Defensive_Military     = Building_Max_Percentage ;
if ( Building_Attacked_Losses        > Building_Max_Percentage ) Building_Attacked_Losses        = Building_Max_Percentage ;
if ( Building_Cure_Plague            > Building_Max_Percentage ) Building_Cure_Plague            = Building_Max_Percentage ;
if ( Building_Military_Losses        > Building_Max_Percentage ) Building_Military_Losses        = Building_Max_Percentage ;
if ( Building_Thievery_Losses        > 95                      ) Building_Thievery_Losses        = 95                      ;
if ( Building_Thievery_Effectiveness > Building_Max_Percentage ) Building_Thievery_Effectiveness = Building_Max_Percentage ;
if ( Building_Catching_Thieves       > Building_Max_Percentage ) Building_Catching_Thieves       = Building_Max_Percentage ;
if ( Building_Thievery_Damage        > Building_Max_Percentage ) Building_Thievery_Damage        = Building_Max_Percentage ;
if ( Building_Science_Effectiveness  > Building_Max_Percentage ) Building_Science_Effectiveness  = Building_Max_Percentage ;
if ( Building_Science_Costs          > Building_Max_Percentage ) Building_Science_Costs          = Building_Max_Percentage ;
if ( Building_Books_Protected        > Building_Max_Percentage ) Building_Books_Protected        = Building_Max_Percentage ;


Building_Increased_Income       = -100 + ( 100 + Building_Increased_Income       ) * Building_Increased_Income_Bonus       ;
Building_Birth_Rate             = -100 + ( 100 + Building_Birth_Rate             ) * Building_Birth_Rate_Bonus             ;
Building_Attack_Time            =  100 - ( 100 - Building_Attack_Time            ) * Building_Attack_Time_Bonus            ;
Building_Offensive_Military     = -100 + ( 100 + Building_Offensive_Military     ) * Building_Offensive_Military_Bonus     ;
Building_Defensive_Military     = -100 + ( 100 + Building_Defensive_Military     ) * Building_Defensive_Military_Bonus     ;
Building_Training_Costs         =  100 - ( 100 - Building_Training_Costs         ) * Building_Training_Costs_Bonus         ;
Building_Daily_Wages            =  100 - ( 100 - Building_Daily_Wages            ) * Building_Daily_Wages_Bonus            ;
Building_Draft_Costs            =  100 - ( 100 - Building_Draft_Costs            ) * Building_Draft_Costs_Bonus            ;
Building_Military_Losses        =  100 - ( 100 - Building_Military_Losses        ) * Building_Military_Losses_Bonus        ;
Building_Construction_Cost      =  100 - ( 100 - Building_Construction_Cost      ) * Building_Construction_Cost_Bonus      ;
Building_Exploration_Cost       =  100 - ( 100 - Building_Exploration_Cost       ) * Building_Exploration_Cost_Bonus       ;
Building_Thievery_Losses        =  100 - ( 100 - Building_Thievery_Losses        ) * Building_Thievery_Losses_Bonus        ;
Building_Thievery_Effectiveness =  100 - ( 100 - Building_Thievery_Effectiveness ) * Building_Thievery_Effectiveness_Bonus ;
Building_Science_Effectiveness  = -100 + ( 100 + Building_Science_Effectiveness  ) * Building_Science_Effectiveness_Bonus  ;
Building_Science_Costs          = -100 + ( 100 + Building_Science_Costs          ) * Building_Science_Costs_Bonus          ;
Building_Books_Protected        =  100 - ( 100 - Building_Books_Protected        ) * Building_Books_Protected_Bonus        ;
Building_Military_Losses        = -100 + ( 100 + Building_Military_Losses        ) * Building_Race_Hospitals_Bonus         ; // Hospitals case 1
Building_Cure_Plague            = -100 + ( 100 + Building_Cure_Plague            ) * Building_Race_Hospitals_Bonus         ; // Hospitals case 2


Building_Total_Jobs = (Building_Available_Total - Building_Progress_Total - Building_Available_Barren - Building_Available_Homes)*25 ;
Building_Total_NW   = (Building_Available_Total - Building_Progress_Total - Building_Available_Barren)*55 + Building_Available_Barren*15 + (Building_Progress_Total - Building_Progress_Barren)*30 ;

if (( Building_Total_Jobs == 0 )&&( Building_Available_Total > 0 )) Building_Total_Jobs = 1 ;

Building_Building_Cost = Math.round( Building_Building_Cost * (100-Building_Construction_Cost)/100);

document.getElementById( 'Building_Building_Cost'          ).innerHTML = Building_Building_Cost ;
document.getElementById( 'Building_Razing_Cost'            ).innerHTML = Building_Razing_Cost   ;
document.getElementById( 'Building_Total_Jobs'             ).innerHTML = Building_Total_Jobs    ;
document.getElementById( 'Building_Total_NW'               ).innerHTML = Building_Total_NW      ;

document.getElementById( 'Building_Max_Efficiency'         ).innerHTML = Math.round( Building_Total_Jobs*0.67 ) ;
document.getElementById( 'Building_Birth_Rate'             ).innerHTML = Math.round( Building_Birth_Rate             * 100 ) / 100;
document.getElementById( 'Building_Construction_Cost'      ).innerHTML = Math.round( Building_Construction_Cost      * 100 ) / 100;
document.getElementById( 'Building_Exploration_Cost'       ).innerHTML = Math.round( Building_Exploration_Cost       * 100 ) / 100;
document.getElementById( 'Building_Increased_Income'       ).innerHTML = Math.round( Building_Increased_Income       * 100 ) / 100;
document.getElementById( 'Building_Offensive_Military'     ).innerHTML = Math.round( Building_Offensive_Military     * 100 ) / 100;
document.getElementById( 'Building_Training_Costs'         ).innerHTML = Math.round( Building_Training_Costs         * 100 ) / 100;
document.getElementById( 'Building_Daily_Wages'            ).innerHTML = Math.round( Building_Daily_Wages            * 100 ) / 100;
document.getElementById( 'Building_Draft_Costs'            ).innerHTML = Math.round( Building_Draft_Costs            * 100 ) / 100;
document.getElementById( 'Building_Attack_Time'            ).innerHTML = Math.round( Building_Attack_Time            * 100 ) / 100;
document.getElementById( 'Building_Attack_Time_QF'         ).innerHTML = Math.round( ( Building_Attack_Time*0.9 + 10       ) * 100 ) / 100;
document.getElementById( 'Building_Defensive_Military'     ).innerHTML = Math.round( Building_Defensive_Military     * 100 ) / 100;
document.getElementById( 'Building_Attacked_Losses'        ).innerHTML = Math.round( Building_Attacked_Losses        * 100 ) / 100;
document.getElementById( 'Building_Cure_Plague'            ).innerHTML = Math.round( Building_Cure_Plague            * 100 ) / 100;
document.getElementById( 'Building_Military_Losses'        ).innerHTML = Math.round( Building_Military_Losses        * 100 ) / 100;
document.getElementById( 'Building_Thievery_Losses'        ).innerHTML = Math.round( Building_Thievery_Losses        * 100 ) / 100;
document.getElementById( 'Building_Thievery_Effectiveness' ).innerHTML = Math.round( Building_Thievery_Effectiveness * 100 ) / 100;
document.getElementById( 'Building_Catching_Thieves'       ).innerHTML = Math.round( Building_Catching_Thieves       * 100 ) / 100;
document.getElementById( 'Building_Thievery_Damage'        ).innerHTML = Math.round( Building_Thievery_Damage        * 100 ) / 100;
document.getElementById( 'Building_Science_Bonus'          ).innerHTML = Math.round( Building_Science_Effectiveness  * 100 ) / 100;
document.getElementById( 'Building_Science_Costs'          ).innerHTML = Math.round( Building_Science_Costs          * 100 ) / 100;
document.getElementById( 'Building_Books_Protected'        ).innerHTML = Math.round( Building_Books_Protected        * 100 ) / 100;

Building_Total_Cost = 0;

if ( document.getElementById('Building_Goal_Total').innerHTML != "0%" ) {

if ( Build_This_Homes     > 0 ) Building_Total_Cost += Build_This_Homes     * Building_Building_Cost ;
if ( Build_This_Farms     > 0 ) Building_Total_Cost += Build_This_Farms     * Building_Building_Cost ;
if ( Build_This_Mills     > 0 ) Building_Total_Cost += Build_This_Mills     * Building_Building_Cost ;
if ( Build_This_Banks     > 0 ) Building_Total_Cost += Build_This_Banks     * Building_Building_Cost ;
if ( Build_This_TG        > 0 ) Building_Total_Cost += Build_This_TG        * Building_Building_Cost ;
if ( Build_This_Armouries > 0 ) Building_Total_Cost += Build_This_Armouries * Building_Building_Cost ;
if ( Build_This_Barracks  > 0 ) Building_Total_Cost += Build_This_Barracks  * Building_Building_Cost ;
if ( Build_This_Forts     > 0 ) Building_Total_Cost += Build_This_Forts     * Building_Building_Cost ;
if ( Build_This_GS        > 0 ) Building_Total_Cost += Build_This_GS        * Building_Building_Cost ;
if ( Build_This_Hospitals > 0 ) Building_Total_Cost += Build_This_Hospitals * Building_Building_Cost ;
if ( Build_This_Guilds    > 0 ) Building_Total_Cost += Build_This_Guilds    * Building_Building_Cost ;
if ( Build_This_Towers    > 0 ) Building_Total_Cost += Build_This_Towers    * Building_Building_Cost ;
if ( Build_This_TD        > 0 ) Building_Total_Cost += Build_This_TD        * Building_Building_Cost ;
if ( Build_This_WT        > 0 ) Building_Total_Cost += Build_This_WT        * Building_Building_Cost ;
if ( Build_This_Libraries > 0 ) Building_Total_Cost += Build_This_Libraries * Building_Building_Cost ;
if ( Build_This_Schools   > 0 ) Building_Total_Cost += Build_This_Schools   * Building_Building_Cost ;
if ( Build_This_Stables   > 0 ) Building_Total_Cost += Build_This_Stables   * Building_Building_Cost ;
if ( Build_This_Dungeons  > 0 ) Building_Total_Cost += Build_This_Dungeons  * Building_Building_Cost ;

if ( Build_This_Homes     < 0 ) Building_Total_Cost -= Build_This_Homes     * Building_Razing_Cost ;
if ( Build_This_Farms     < 0 ) Building_Total_Cost -= Build_This_Farms     * Building_Razing_Cost ;
if ( Build_This_Mills     < 0 ) Building_Total_Cost -= Build_This_Mills     * Building_Razing_Cost ;
if ( Build_This_Banks     < 0 ) Building_Total_Cost -= Build_This_Banks     * Building_Razing_Cost ;
if ( Build_This_TG        < 0 ) Building_Total_Cost -= Build_This_TG        * Building_Razing_Cost ;
if ( Build_This_Armouries < 0 ) Building_Total_Cost -= Build_This_Armouries * Building_Razing_Cost ;
if ( Build_This_Barracks  < 0 ) Building_Total_Cost -= Build_This_Barracks  * Building_Razing_Cost ;
if ( Build_This_Forts     < 0 ) Building_Total_Cost -= Build_This_Forts     * Building_Razing_Cost ;
if ( Build_This_GS        < 0 ) Building_Total_Cost -= Build_This_GS        * Building_Razing_Cost ;
if ( Build_This_Hospitals < 0 ) Building_Total_Cost -= Build_This_Hospitals * Building_Razing_Cost ;
if ( Build_This_Guilds    < 0 ) Building_Total_Cost -= Build_This_Guilds    * Building_Razing_Cost ;
if ( Build_This_Towers    < 0 ) Building_Total_Cost -= Build_This_Towers    * Building_Razing_Cost ;
if ( Build_This_TD        < 0 ) Building_Total_Cost -= Build_This_TD        * Building_Razing_Cost ;
if ( Build_This_WT        < 0 ) Building_Total_Cost -= Build_This_WT        * Building_Razing_Cost ;
if ( Build_This_Libraries < 0 ) Building_Total_Cost -= Build_This_Libraries * Building_Razing_Cost ;
if ( Build_This_Schools   < 0 ) Building_Total_Cost -= Build_This_Schools   * Building_Razing_Cost ;
if ( Build_This_Stables   < 0 ) Building_Total_Cost -= Build_This_Stables   * Building_Razing_Cost ;
if ( Build_This_Dungeons  < 0 ) Building_Total_Cost -= Build_This_Dungeons  * Building_Razing_Cost ;

}

document.getElementById('Building_Total_Cost').innerHTML = Building_Total_Cost ;


}


function Building_Clear_Column1() {
document.getElementById('Building_Available_Barren').value    = 0;
document.getElementById('Building_Available_Homes').value     = 0;
document.getElementById('Building_Available_Farms').value     = 0;
document.getElementById('Building_Available_Mills').value     = 0;
document.getElementById('Building_Available_Banks').value     = 0;
document.getElementById('Building_Available_TG').value        = 0;
document.getElementById('Building_Available_Armouries').value = 0;
document.getElementById('Building_Available_Barracks').value  = 0;
document.getElementById('Building_Available_Forts').value     = 0;
document.getElementById('Building_Available_GS').value        = 0;
document.getElementById('Building_Available_Hospitals').value = 0;
document.getElementById('Building_Available_Guilds').value    = 0;
document.getElementById('Building_Available_Towers').value    = 0;
document.getElementById('Building_Available_TD').value        = 0;
document.getElementById('Building_Available_WT').value        = 0;
document.getElementById('Building_Available_Libraries').value = 0;
document.getElementById('Building_Available_Schools').value   = 0;
document.getElementById('Building_Available_Stables').value   = 0;
document.getElementById('Building_Available_Dungeons').value  = 0;
}

function Building_Clear_Column2() {
document.getElementById('Building_Progress_Barren').value    = 0;
document.getElementById('Building_Progress_Homes').value     = 0;
document.getElementById('Building_Progress_Farms').value     = 0;
document.getElementById('Building_Progress_Mills').value     = 0;
document.getElementById('Building_Progress_Banks').value     = 0;
document.getElementById('Building_Progress_TG').value        = 0;
document.getElementById('Building_Progress_Armouries').value = 0;
document.getElementById('Building_Progress_Barracks').value  = 0;
document.getElementById('Building_Progress_Forts').value     = 0;
document.getElementById('Building_Progress_GS').value        = 0;
document.getElementById('Building_Progress_Hospitals').value = 0;
document.getElementById('Building_Progress_Guilds').value    = 0;
document.getElementById('Building_Progress_Towers').value    = 0;
document.getElementById('Building_Progress_TD').value        = 0;
document.getElementById('Building_Progress_WT').value        = 0;
document.getElementById('Building_Progress_Libraries').value = 0;
document.getElementById('Building_Progress_Schools').value   = 0;
document.getElementById('Building_Progress_Stables').value   = 0;
document.getElementById('Building_Progress_Dungeons').value  = 0;
}

function Building_Clear_Column3() {
document.getElementById('Building_Goal_Barren').value    = 0;
document.getElementById('Building_Goal_Homes').value     = 0;
document.getElementById('Building_Goal_Farms').value     = 0;
document.getElementById('Building_Goal_Mills').value     = 0;
document.getElementById('Building_Goal_Banks').value     = 0;
document.getElementById('Building_Goal_TG').value        = 0;
document.getElementById('Building_Goal_Armouries').value = 0;
document.getElementById('Building_Goal_Barracks').value  = 0;
document.getElementById('Building_Goal_Forts').value     = 0;
document.getElementById('Building_Goal_GS').value        = 0;
document.getElementById('Building_Goal_Hospitals').value = 0;
document.getElementById('Building_Goal_Guilds').value    = 0;
document.getElementById('Building_Goal_Towers').value    = 0;
document.getElementById('Building_Goal_TD').value        = 0;
document.getElementById('Building_Goal_WT').value        = 0;
document.getElementById('Building_Goal_Libraries').value = 0;
document.getElementById('Building_Goal_Schools').value   = 0;
document.getElementById('Building_Goal_Stables').value   = 0;
document.getElementById('Building_Goal_Dungeons').value  = 0;
}

function Building_Clear_All_Columns() {
Building_Clear_Column1();
Building_Clear_Column2();
Building_Clear_Column3();
}


function Building_Reset_Info() {

document.getElementById('Building_Percentage_Ratio').value = "Percentage";

document.getElementById('Building_War_Box').checked = false;
document.getElementById('Building_Bonuses_Box').checked = false;
document.getElementById('Building_Progress_Box').checked = false;
document.getElementById('Building_Goal_Box').checked = false;

document.getElementById('Building_Stance').value = 0;
document.getElementById('Building_Race').value = 0;
document.getElementById('Building_Personality').value = 0;
document.getElementById('Building_Effectiveness').value = 100;

Building_Available_Workers   = 0;
Building_Total_Money         = 0;

}


function Building_Reset_All_Info() { Building_Clear_All_Columns(); Building_Reset_Info(); }

function BuildingExpandCompact() {

if (document.getElementById('Building_Expand_Compact').value == "Expand" ) {

document.getElementById('Building_Expand_Compact').value = "Compact" ;

document.getElementById( 'Building_ID_Barren'    ).style.display = "";
document.getElementById( 'Building_ID_Homes'     ).style.display = "";
document.getElementById( 'Building_ID_Farms'     ).style.display = "";
document.getElementById( 'Building_ID_Mills'     ).style.display = "";
document.getElementById( 'Building_ID_Banks'     ).style.display = "";
document.getElementById( 'Building_ID_TG'        ).style.display = "";
document.getElementById( 'Building_ID_Armouries' ).style.display = "";
document.getElementById( 'Building_ID_Barracks'  ).style.display = "";
document.getElementById( 'Building_ID_Forts'     ).style.display = "";
document.getElementById( 'Building_ID_GS'        ).style.display = "";
document.getElementById( 'Building_ID_Hospitals' ).style.display = "";
document.getElementById( 'Building_ID_Guilds'    ).style.display = "";
document.getElementById( 'Building_ID_Towers'    ).style.display = "";
document.getElementById( 'Building_ID_TD'        ).style.display = "";
document.getElementById( 'Building_ID_WT'        ).style.display = "";
document.getElementById( 'Building_ID_Libraries' ).style.display = "";
document.getElementById( 'Building_ID_Schools'   ).style.display = "";
document.getElementById( 'Building_ID_Stables'   ).style.display = "";
document.getElementById( 'Building_ID_Dungeons'  ).style.display = "";

} else {

document.getElementById('Building_Expand_Compact').value = "Expand" ;

if ( Building_Available_Barren    + Building_Progress_Barren    + Building_Goal_Barren    == 0 ) document.getElementById( 'Building_ID_Barren'    ).style.display = "none";
if ( Building_Available_Homes     + Building_Progress_Homes     + Building_Goal_Homes     == 0 ) document.getElementById( 'Building_ID_Homes'     ).style.display = "none";
if ( Building_Available_Farms     + Building_Progress_Farms     + Building_Goal_Farms     == 0 ) document.getElementById( 'Building_ID_Farms'     ).style.display = "none";
if ( Building_Available_Mills     + Building_Progress_Mills     + Building_Goal_Mills     == 0 ) document.getElementById( 'Building_ID_Mills'     ).style.display = "none";
if ( Building_Available_Banks     + Building_Progress_Banks     + Building_Goal_Banks     == 0 ) document.getElementById( 'Building_ID_Banks'     ).style.display = "none";
if ( Building_Available_TG        + Building_Progress_TG        + Building_Goal_TG        == 0 ) document.getElementById( 'Building_ID_TG'        ).style.display = "none";
if ( Building_Available_Armouries + Building_Progress_Armouries + Building_Goal_Armouries == 0 ) document.getElementById( 'Building_ID_Armouries' ).style.display = "none";
if ( Building_Available_Barracks  + Building_Progress_Barracks  + Building_Goal_Barracks  == 0 ) document.getElementById( 'Building_ID_Barracks'  ).style.display = "none";
if ( Building_Available_Forts     + Building_Progress_Forts     + Building_Goal_Forts     == 0 ) document.getElementById( 'Building_ID_Forts'     ).style.display = "none";
if ( Building_Available_GS        + Building_Progress_GS        + Building_Goal_GS        == 0 ) document.getElementById( 'Building_ID_GS'        ).style.display = "none";
if ( Building_Available_Hospitals + Building_Progress_Hospitals + Building_Goal_Hospitals == 0 ) document.getElementById( 'Building_ID_Hospitals' ).style.display = "none";
if ( Building_Available_Guilds    + Building_Progress_Guilds    + Building_Goal_Guilds    == 0 ) document.getElementById( 'Building_ID_Guilds'    ).style.display = "none";
if ( Building_Available_Towers    + Building_Progress_Towers    + Building_Goal_Towers    == 0 ) document.getElementById( 'Building_ID_Towers'    ).style.display = "none";
if ( Building_Available_TD        + Building_Progress_TD        + Building_Goal_TD        == 0 ) document.getElementById( 'Building_ID_TD'        ).style.display = "none";
if ( Building_Available_WT        + Building_Progress_WT        + Building_Goal_WT        == 0 ) document.getElementById( 'Building_ID_WT'        ).style.display = "none";
if ( Building_Available_Libraries + Building_Progress_Libraries + Building_Goal_Libraries == 0 ) document.getElementById( 'Building_ID_Libraries' ).style.display = "none";
if ( Building_Available_Schools   + Building_Progress_Schools   + Building_Goal_Schools   == 0 ) document.getElementById( 'Building_ID_Schools'   ).style.display = "none";
if ( Building_Available_Stables   + Building_Progress_Stables   + Building_Goal_Stables   == 0 ) document.getElementById( 'Building_ID_Stables'   ).style.display = "none";
if ( Building_Available_Dungeons  + Building_Progress_Dungeons  + Building_Goal_Dungeons  == 0 ) document.getElementById( 'Building_ID_Dungeons'  ).style.display = "none";

}

window.sizeToContent();

}

function BuildingPercentageRatio() { if (document.getElementById('Building_Percentage_Ratio').value=="Percentage") {
document.getElementById('Building_Percentage_Ratio').value="Ratio"; } else { document.getElementById('Building_Percentage_Ratio').value="Percentage"; } }

function Building_Ready_Column() {

Building_Available_Barren    += Building_Progress_Barren ;
Building_Available_Homes     += Building_Progress_Homes ;
Building_Available_Farms     += Building_Progress_Farms ;
Building_Available_Mills     += Building_Progress_Mills ;
Building_Available_Banks     += Building_Progress_Banks ;
Building_Available_TG        += Building_Progress_TG ;
Building_Available_Armouries += Building_Progress_Armouries ;
Building_Available_Barracks  += Building_Progress_Barracks ;
Building_Available_Forts     += Building_Progress_Forts ;
Building_Available_GS        += Building_Progress_GS ;
Building_Available_Hospitals += Building_Progress_Hospitals ;
Building_Available_Guilds    += Building_Progress_Guilds ;
Building_Available_Towers    += Building_Progress_Towers ;
Building_Available_TD        += Building_Progress_TD ;
Building_Available_WT        += Building_Progress_WT ;
Building_Available_Libraries += Building_Progress_Libraries ;
Building_Available_Schools   += Building_Progress_Schools ;
Building_Available_Stables   += Building_Progress_Stables ;
Building_Available_Dungeons  += Building_Progress_Dungeons ;

Building_Clear_Column2();

document.getElementById( 'Building_Available_Barren'    ).value = Building_Available_Barren;
document.getElementById( 'Building_Available_Homes'     ).value = Building_Available_Homes;
document.getElementById( 'Building_Available_Farms'     ).value = Building_Available_Farms;
document.getElementById( 'Building_Available_Mills'     ).value = Building_Available_Mills;
document.getElementById( 'Building_Available_Banks'     ).value = Building_Available_Banks;
document.getElementById( 'Building_Available_TG'        ).value = Building_Available_TG;
document.getElementById( 'Building_Available_Armouries' ).value = Building_Available_Armouries;
document.getElementById( 'Building_Available_Barracks'  ).value = Building_Available_Barracks;
document.getElementById( 'Building_Available_Forts'     ).value = Building_Available_Forts;
document.getElementById( 'Building_Available_GS'        ).value = Building_Available_GS;
document.getElementById( 'Building_Available_Hospitals' ).value = Building_Available_Hospitals;
document.getElementById( 'Building_Available_Guilds'    ).value = Building_Available_Guilds;
document.getElementById( 'Building_Available_Towers'    ).value = Building_Available_Towers;
document.getElementById( 'Building_Available_TD'        ).value = Building_Available_TD;
document.getElementById( 'Building_Available_WT'        ).value = Building_Available_WT;
document.getElementById( 'Building_Available_Libraries' ).value = Building_Available_Libraries;
document.getElementById( 'Building_Available_Schools'   ).value = Building_Available_Schools;
document.getElementById( 'Building_Available_Stables'   ).value = Building_Available_Stables;
document.getElementById( 'Building_Available_Dungeons'  ).value = Building_Available_Dungeons;

}

function Building_Build_Column() {

Building_Ready_Column();

Building_Available_Barren    += Build_This_Barren ;
Building_Available_Homes     += Build_This_Homes ;
Building_Available_Farms     += Build_This_Farms ;
Building_Available_Mills     += Build_This_Mills ;
Building_Available_Banks     += Build_This_Banks ;
Building_Available_TG        += Build_This_TG ;
Building_Available_Armouries += Build_This_Armouries ;
Building_Available_Barracks  += Build_This_Barracks ;
Building_Available_Forts     += Build_This_Forts ;
Building_Available_GS        += Build_This_GS ;
Building_Available_Hospitals += Build_This_Hospitals ;
Building_Available_Guilds    += Build_This_Guilds ;
Building_Available_Towers    += Build_This_Towers ;
Building_Available_TD        += Build_This_TD ;
Building_Available_WT        += Build_This_WT ;
Building_Available_Libraries += Build_This_Libraries ;
Building_Available_Schools   += Build_This_Schools ;
Building_Available_Stables   += Build_This_Stables ;
Building_Available_Dungeons  += Build_This_Dungeons ;

document.getElementById( 'Building_Available_Barren'    ).value = Building_Available_Barren;
document.getElementById( 'Building_Available_Homes'     ).value = Building_Available_Homes;
document.getElementById( 'Building_Available_Farms'     ).value = Building_Available_Farms;
document.getElementById( 'Building_Available_Mills'     ).value = Building_Available_Mills;
document.getElementById( 'Building_Available_Banks'     ).value = Building_Available_Banks;
document.getElementById( 'Building_Available_TG'        ).value = Building_Available_TG;
document.getElementById( 'Building_Available_Armouries' ).value = Building_Available_Armouries;
document.getElementById( 'Building_Available_Barracks'  ).value = Building_Available_Barracks;
document.getElementById( 'Building_Available_Forts'     ).value = Building_Available_Forts;
document.getElementById( 'Building_Available_GS'        ).value = Building_Available_GS;
document.getElementById( 'Building_Available_Hospitals' ).value = Building_Available_Hospitals;
document.getElementById( 'Building_Available_Guilds'    ).value = Building_Available_Guilds;
document.getElementById( 'Building_Available_Towers'    ).value = Building_Available_Towers;
document.getElementById( 'Building_Available_TD'        ).value = Building_Available_TD;
document.getElementById( 'Building_Available_WT'        ).value = Building_Available_WT;
document.getElementById( 'Building_Available_Libraries' ).value = Building_Available_Libraries;
document.getElementById( 'Building_Available_Schools'   ).value = Building_Available_Schools;
document.getElementById( 'Building_Available_Stables'   ).value = Building_Available_Stables;
document.getElementById( 'Building_Available_Dungeons'  ).value = Building_Available_Dungeons;

}

function BuildingGenerateReport() {

textonly=""+c0+"Survey / Buildings Report Information"+cc+Copyrights;

if ( Building_Prov != "" ) textonly += "<br />"+c1+"Ruler Name: "+cc+c2+ Building_Prov +cc;

textonly += ""+

"<br />"+c1+"Personality & Race: "  +cc+c2+ Building_Personality         +cc+c1+", "+cc+c2+Building_Race+cc+
"<br />"+c1+"Stance: "              +cc+c2+ Building_Stance              +cc+
"<br />"+c1+"Building Cost: "       +cc+c2+ Building_Building_Cost       +cc+c1+"gc"+cc+
"<br />"+c1+"Razing Cost: "         +cc+c2+ Building_Razing_Cost         +cc+c1+"gc"+cc+
"<br />"+c1+"Total Jobs: "          +cc+c2+ Building_Total_Jobs          +cc+
"<br />"+c1+"Total Networth: "      +cc+c2+ Building_Total_NW            +cc+c1+"gc"+cc+
"<br />"+c1+"Building Efficiency: " +cc+c2+ Building_Effectiveness       +"%"+cc+
"<br />";

var xx=0;

if (( Building_Available_Barren    != 0 )||( Building_Progress_Barren    != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Barren: "    +cc; } if ( Building_Available_Barren    != 0 ) textonly += c2+ Building_Available_Barren    +cc+c1+" ("+cc+c2+ Building_Percentage_Barren    +"%"+cc+c1+") " ; if (( Building_Available_Barren    != 0 )&&( Building_Progress_Barren    != 0 )) textonly += "+ "; if ( Building_Progress_Barren    != 0 ) textonly += cc+c2+ Building_Progress_Barren    +cc+c1+ " in progress (+" + Math.round( Building_Progress_Barren    / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Homes     != 0 )||( Building_Progress_Homes     != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Homes: "     +cc; } if ( Building_Available_Homes     != 0 ) textonly += c2+ Building_Available_Homes     +cc+c1+" ("+cc+c2+ Building_Percentage_Homes     +"%"+cc+c1+") " ; if (( Building_Available_Homes     != 0 )&&( Building_Progress_Homes     != 0 )) textonly += "+ "; if ( Building_Progress_Homes     != 0 ) textonly += cc+c2+ Building_Progress_Homes     +cc+c1+ " in progress (+" + Math.round( Building_Progress_Homes     / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Farms     != 0 )||( Building_Progress_Farms     != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Farms: "     +cc; } if ( Building_Available_Farms     != 0 ) textonly += c2+ Building_Available_Farms     +cc+c1+" ("+cc+c2+ Building_Percentage_Farms     +"%"+cc+c1+") " ; if (( Building_Available_Farms     != 0 )&&( Building_Progress_Farms     != 0 )) textonly += "+ "; if ( Building_Progress_Farms     != 0 ) textonly += cc+c2+ Building_Progress_Farms     +cc+c1+ " in progress (+" + Math.round( Building_Progress_Farms     / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Mills     != 0 )||( Building_Progress_Mills     != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Mills: "     +cc; } if ( Building_Available_Mills     != 0 ) textonly += c2+ Building_Available_Mills     +cc+c1+" ("+cc+c2+ Building_Percentage_Mills     +"%"+cc+c1+") " ; if (( Building_Available_Mills     != 0 )&&( Building_Progress_Mills     != 0 )) textonly += "+ "; if ( Building_Progress_Mills     != 0 ) textonly += cc+c2+ Building_Progress_Mills     +cc+c1+ " in progress (+" + Math.round( Building_Progress_Mills     / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Banks     != 0 )||( Building_Progress_Banks     != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Banks: "     +cc; } if ( Building_Available_Banks     != 0 ) textonly += c2+ Building_Available_Banks     +cc+c1+" ("+cc+c2+ Building_Percentage_Banks     +"%"+cc+c1+") " ; if (( Building_Available_Banks     != 0 )&&( Building_Progress_Banks     != 0 )) textonly += "+ "; if ( Building_Progress_Banks     != 0 ) textonly += cc+c2+ Building_Progress_Banks     +cc+c1+ " in progress (+" + Math.round( Building_Progress_Banks     / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_TG        != 0 )||( Building_Progress_TG        != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". TG: "        +cc; } if ( Building_Available_TG        != 0 ) textonly += c2+ Building_Available_TG        +cc+c1+" ("+cc+c2+ Building_Percentage_TG        +"%"+cc+c1+") " ; if (( Building_Available_TG        != 0 )&&( Building_Progress_TG        != 0 )) textonly += "+ "; if ( Building_Progress_TG        != 0 ) textonly += cc+c2+ Building_Progress_TG        +cc+c1+ " in progress (+" + Math.round( Building_Progress_TG        / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Armouries != 0 )||( Building_Progress_Armouries != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Armouries: " +cc; } if ( Building_Available_Armouries != 0 ) textonly += c2+ Building_Available_Armouries +cc+c1+" ("+cc+c2+ Building_Percentage_Armouries +"%"+cc+c1+") " ; if (( Building_Available_Armouries != 0 )&&( Building_Progress_Armouries != 0 )) textonly += "+ "; if ( Building_Progress_Armouries != 0 ) textonly += cc+c2+ Building_Progress_Armouries +cc+c1+ " in progress (+" + Math.round( Building_Progress_Armouries / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Barracks  != 0 )||( Building_Progress_Barracks  != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Barracks: "  +cc; } if ( Building_Available_Barracks  != 0 ) textonly += c2+ Building_Available_Barracks  +cc+c1+" ("+cc+c2+ Building_Percentage_Barracks  +"%"+cc+c1+") " ; if (( Building_Available_Barracks  != 0 )&&( Building_Progress_Barracks  != 0 )) textonly += "+ "; if ( Building_Progress_Barracks  != 0 ) textonly += cc+c2+ Building_Progress_Barracks  +cc+c1+ " in progress (+" + Math.round( Building_Progress_Barracks  / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Forts     != 0 )||( Building_Progress_Forts     != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Forts: "     +cc; } if ( Building_Available_Forts     != 0 ) textonly += c2+ Building_Available_Forts     +cc+c1+" ("+cc+c2+ Building_Percentage_Forts     +"%"+cc+c1+") " ; if (( Building_Available_Forts     != 0 )&&( Building_Progress_Forts     != 0 )) textonly += "+ "; if ( Building_Progress_Forts     != 0 ) textonly += cc+c2+ Building_Progress_Forts     +cc+c1+ " in progress (+" + Math.round( Building_Progress_Forts     / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_GS        != 0 )||( Building_Progress_GS        != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". GS: "        +cc; } if ( Building_Available_GS        != 0 ) textonly += c2+ Building_Available_GS        +cc+c1+" ("+cc+c2+ Building_Percentage_GS        +"%"+cc+c1+") " ; if (( Building_Available_GS        != 0 )&&( Building_Progress_GS        != 0 )) textonly += "+ "; if ( Building_Progress_GS        != 0 ) textonly += cc+c2+ Building_Progress_GS        +cc+c1+ " in progress (+" + Math.round( Building_Progress_GS        / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Hospitals != 0 )||( Building_Progress_Hospitals != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Hospitals: " +cc; } if ( Building_Available_Hospitals != 0 ) textonly += c2+ Building_Available_Hospitals +cc+c1+" ("+cc+c2+ Building_Percentage_Hospitals +"%"+cc+c1+") " ; if (( Building_Available_Hospitals != 0 )&&( Building_Progress_Hospitals != 0 )) textonly += "+ "; if ( Building_Progress_Hospitals != 0 ) textonly += cc+c2+ Building_Progress_Hospitals +cc+c1+ " in progress (+" + Math.round( Building_Progress_Hospitals / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Guilds    != 0 )||( Building_Progress_Guilds    != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Guilds: "    +cc; } if ( Building_Available_Guilds    != 0 ) textonly += c2+ Building_Available_Guilds    +cc+c1+" ("+cc+c2+ Building_Percentage_Guilds    +"%"+cc+c1+") " ; if (( Building_Available_Guilds    != 0 )&&( Building_Progress_Guilds    != 0 )) textonly += "+ "; if ( Building_Progress_Guilds    != 0 ) textonly += cc+c2+ Building_Progress_Guilds    +cc+c1+ " in progress (+" + Math.round( Building_Progress_Guilds    / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Towers    != 0 )||( Building_Progress_Towers    != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Towers: "    +cc; } if ( Building_Available_Towers    != 0 ) textonly += c2+ Building_Available_Towers    +cc+c1+" ("+cc+c2+ Building_Percentage_Towers    +"%"+cc+c1+") " ; if (( Building_Available_Towers    != 0 )&&( Building_Progress_Towers    != 0 )) textonly += "+ "; if ( Building_Progress_Towers    != 0 ) textonly += cc+c2+ Building_Progress_Towers    +cc+c1+ " in progress (+" + Math.round( Building_Progress_Towers    / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_TD        != 0 )||( Building_Progress_TD        != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". TD: "        +cc; } if ( Building_Available_TD        != 0 ) textonly += c2+ Building_Available_TD        +cc+c1+" ("+cc+c2+ Building_Percentage_TD        +"%"+cc+c1+") " ; if (( Building_Available_TD        != 0 )&&( Building_Progress_TD        != 0 )) textonly += "+ "; if ( Building_Progress_TD        != 0 ) textonly += cc+c2+ Building_Progress_TD        +cc+c1+ " in progress (+" + Math.round( Building_Progress_TD        / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_WT        != 0 )||( Building_Progress_WT        != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". WT: "        +cc; } if ( Building_Available_WT        != 0 ) textonly += c2+ Building_Available_WT        +cc+c1+" ("+cc+c2+ Building_Percentage_WT        +"%"+cc+c1+") " ; if (( Building_Available_WT        != 0 )&&( Building_Progress_WT        != 0 )) textonly += "+ "; if ( Building_Progress_WT        != 0 ) textonly += cc+c2+ Building_Progress_WT        +cc+c1+ " in progress (+" + Math.round( Building_Progress_WT        / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Libraries != 0 )||( Building_Progress_Libraries != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Libraries: " +cc; } if ( Building_Available_Libraries != 0 ) textonly += c2+ Building_Available_Libraries +cc+c1+" ("+cc+c2+ Building_Percentage_Libraries +"%"+cc+c1+") " ; if (( Building_Available_Libraries != 0 )&&( Building_Progress_Libraries != 0 )) textonly += "+ "; if ( Building_Progress_Libraries != 0 ) textonly += cc+c2+ Building_Progress_Libraries +cc+c1+ " in progress (+" + Math.round( Building_Progress_Libraries / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Schools   != 0 )||( Building_Progress_Schools   != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Schools: "   +cc; } if ( Building_Available_Schools   != 0 ) textonly += c2+ Building_Available_Schools   +cc+c1+" ("+cc+c2+ Building_Percentage_Schools   +"%"+cc+c1+") " ; if (( Building_Available_Schools   != 0 )&&( Building_Progress_Schools   != 0 )) textonly += "+ "; if ( Building_Progress_Schools   != 0 ) textonly += cc+c2+ Building_Progress_Schools   +cc+c1+ " in progress (+" + Math.round( Building_Progress_Schools   / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Stables   != 0 )||( Building_Progress_Stables   != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Stables: "   +cc; } if ( Building_Available_Stables   != 0 ) textonly += c2+ Building_Available_Stables   +cc+c1+" ("+cc+c2+ Building_Percentage_Stables   +"%"+cc+c1+") " ; if (( Building_Available_Stables   != 0 )&&( Building_Progress_Stables   != 0 )) textonly += "+ "; if ( Building_Progress_Stables   != 0 ) textonly += cc+c2+ Building_Progress_Stables   +cc+c1+ " in progress (+" + Math.round( Building_Progress_Stables   / Building_Available_Total * 1000 ) /10 + "%)" +cc ;
if (( Building_Available_Dungeons  != 0 )||( Building_Progress_Dungeons  != 0 )) { xx+=1; textonly += "<br />"+c1+xx+". Dungeons: "  +cc; } if ( Building_Available_Dungeons  != 0 ) textonly += c2+ Building_Available_Dungeons  +cc+c1+" ("+cc+c2+ Building_Percentage_Dungeons  +"%"+cc+c1+") " ; if (( Building_Available_Dungeons  != 0 )&&( Building_Progress_Dungeons  != 0 )) textonly += "+ "; if ( Building_Progress_Dungeons  != 0 ) textonly += cc+c2+ Building_Progress_Dungeons  +cc+c1+ " in progress (+" + Math.round( Building_Progress_Dungeons  / Building_Available_Total * 1000 ) /10 + "%)" +cc ;

textonly += "<br />"+
"<br />"+c1+"Total Land: "      +cc+c2+ Building_Available_Total     +cc+c1+" Acres"+cc+
"<br />"+c1+"In Progress: "     +cc+c2+ Building_Progress_Total      +cc+c1+" Acres"+cc;

textonly = textonly.replace(/\//g, "");
textonly = textonly.replace(/http:/g, "http://");
textonly = textonly.replace(/  /g, " / ");
textonly = textonly.replace(/<font color='#aa8822'>/g, "");
textonly = textonly.replace(/<font>/g, "");
textonly = textonly.replace(/<font color='#888888'>/g, "");
textonly = textonly.replace(/<font color='#ff0000'>/g, "");
textonly = textonly.replace(/<font>/g, "");

}

document.getElementById( 'Building_Available_Barren'    ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Barren'     );
document.getElementById( 'Building_Available_Homes'     ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Homes'      );
document.getElementById( 'Building_Available_Farms'     ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Farms'      );
document.getElementById( 'Building_Available_Mills'     ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Mills'      );
document.getElementById( 'Building_Available_Banks'     ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Banks'      );
document.getElementById( 'Building_Available_TG'        ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_TG'         );
document.getElementById( 'Building_Available_Armouries' ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Armouries'  );
document.getElementById( 'Building_Available_Barracks'  ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Barracks'   );
document.getElementById( 'Building_Available_Forts'     ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Forts'      );
document.getElementById( 'Building_Available_GS'        ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_GS'         );
document.getElementById( 'Building_Available_Hospitals' ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Hospitals'  );
document.getElementById( 'Building_Available_Guilds'    ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Guilds'     );
document.getElementById( 'Building_Available_Towers'    ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Towers'     );
document.getElementById( 'Building_Available_TD'        ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_TD'         );
document.getElementById( 'Building_Available_WT'        ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_WT'         );
document.getElementById( 'Building_Available_Libraries' ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Libraries'  );
document.getElementById( 'Building_Available_Schools'   ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Schools'    );
document.getElementById( 'Building_Available_Stables'   ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Stables'    );
document.getElementById( 'Building_Available_Dungeons'  ).value = prefService.getIntPref( 'extensions.Ultima.Building_Available_Dungeons'   );

document.getElementById( 'Building_Progress_Barren'     ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Barren'      );
document.getElementById( 'Building_Progress_Homes'      ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Homes'       );
document.getElementById( 'Building_Progress_Farms'      ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Farms'       );
document.getElementById( 'Building_Progress_Mills'      ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Mills'       );
document.getElementById( 'Building_Progress_Banks'      ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Banks'       );
document.getElementById( 'Building_Progress_TG'         ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_TG'          );
document.getElementById( 'Building_Progress_Armouries'  ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Armouries'   );
document.getElementById( 'Building_Progress_Barracks'   ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Barracks'    );
document.getElementById( 'Building_Progress_Forts'      ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Forts'       );
document.getElementById( 'Building_Progress_GS'         ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_GS'          );
document.getElementById( 'Building_Progress_Hospitals'  ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Hospitals'   );
document.getElementById( 'Building_Progress_Guilds'     ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Guilds'      );
document.getElementById( 'Building_Progress_Towers'     ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Towers'      );
document.getElementById( 'Building_Progress_TD'         ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_TD'          );
document.getElementById( 'Building_Progress_WT'         ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_WT'          );
document.getElementById( 'Building_Progress_Libraries'  ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Libraries'   );
document.getElementById( 'Building_Progress_Schools'    ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Schools'     );
document.getElementById( 'Building_Progress_Stables'    ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Stables'     );
document.getElementById( 'Building_Progress_Dungeons'   ).value = prefService.getIntPref( 'extensions.Ultima.Building_Progress_Dungeons'    );

document.getElementById( 'Building_Goal_Barren'         ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Barren'          );
document.getElementById( 'Building_Goal_Homes'          ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Homes'           );
document.getElementById( 'Building_Goal_Farms'          ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Farms'           );
document.getElementById( 'Building_Goal_Mills'          ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Mills'           );
document.getElementById( 'Building_Goal_Banks'          ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Banks'           );
document.getElementById( 'Building_Goal_TG'             ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_TG'              );
document.getElementById( 'Building_Goal_Armouries'      ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Armouries'       );
document.getElementById( 'Building_Goal_Barracks'       ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Barracks'        );
document.getElementById( 'Building_Goal_Forts'          ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Forts'           );
document.getElementById( 'Building_Goal_GS'             ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_GS'              );
document.getElementById( 'Building_Goal_Hospitals'      ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Hospitals'       );
document.getElementById( 'Building_Goal_Guilds'         ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Guilds'          );
document.getElementById( 'Building_Goal_Towers'         ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Towers'          );
document.getElementById( 'Building_Goal_TD'             ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_TD'              );
document.getElementById( 'Building_Goal_WT'             ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_WT'              );
document.getElementById( 'Building_Goal_Libraries'      ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Libraries'       );
document.getElementById( 'Building_Goal_Schools'        ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Schools'         );
document.getElementById( 'Building_Goal_Stables'        ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Stables'         );
document.getElementById( 'Building_Goal_Dungeons'       ).value = prefService.getIntPref( 'extensions.Ultima.Building_Goal_Dungeons'        );

document.getElementById( 'Building_Stance'              ).value = prefService.getIntPref( 'extensions.Ultima.Building_Stance'               );
document.getElementById( 'Building_Race'                ).value = prefService.getIntPref( 'extensions.Ultima.Building_Race'                 );
document.getElementById( 'Building_Personality'         ).value = prefService.getIntPref( 'extensions.Ultima.Building_Personality'          );
document.getElementById( 'Building_Effectiveness'       ).value = prefService.getIntPref( 'extensions.Ultima.Building_Effectiveness'        ) / 100 ;
document.getElementById( 'Building_Percentage_Ratio'    ).value = prefService.getCharPref( 'extensions.Ultima.Building_Percentage_Ratio'    );
document.getElementById( 'Building_Expand_Compact'      ).value = prefService.getCharPref( 'extensions.Ultima.Building_Expand_Compact'      );
document.getElementById( 'Building_War_Box'           ).checked = prefService.getBoolPref( 'extensions.Ultima.Building_War_Box'             );
document.getElementById( 'Building_Bonuses_Box'       ).checked = prefService.getBoolPref( 'extensions.Ultima.Building_Bonuses_Box'         );
document.getElementById( 'Building_Progress_Box'      ).checked = prefService.getBoolPref( 'extensions.Ultima.Building_Progress_Box'        );
document.getElementById( 'Building_Goal_Box'          ).checked = prefService.getBoolPref( 'extensions.Ultima.Building_Goal_Box'            );

document.getElementById( 'Building_Available_Workers' ).innerHTML = prefService.getIntPref( 'extensions.Ultima.Building_Available_Workers'  );
document.getElementById( 'Building_Total_Money'       ).innerHTML = prefService.getIntPref( 'extensions.Ultima.Building_Total_Money'        );

function SaveAllValues() {

prefService.setIntPref( 'extensions.Ultima.Building_Available_Barren'     , document.getElementById( 'Building_Available_Barren'    ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Homes'      , document.getElementById( 'Building_Available_Homes'     ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Farms'      , document.getElementById( 'Building_Available_Farms'     ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Mills'      , document.getElementById( 'Building_Available_Mills'     ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Banks'      , document.getElementById( 'Building_Available_Banks'     ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_TG'         , document.getElementById( 'Building_Available_TG'        ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Armouries'  , document.getElementById( 'Building_Available_Armouries' ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Barracks'   , document.getElementById( 'Building_Available_Barracks'  ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Forts'      , document.getElementById( 'Building_Available_Forts'     ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_GS'         , document.getElementById( 'Building_Available_GS'        ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Hospitals'  , document.getElementById( 'Building_Available_Hospitals' ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Guilds'     , document.getElementById( 'Building_Available_Guilds'    ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Towers'     , document.getElementById( 'Building_Available_Towers'    ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_TD'         , document.getElementById( 'Building_Available_TD'        ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_WT'         , document.getElementById( 'Building_Available_WT'        ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Libraries'  , document.getElementById( 'Building_Available_Libraries' ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Schools'    , document.getElementById( 'Building_Available_Schools'   ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Stables'    , document.getElementById( 'Building_Available_Stables'   ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Available_Dungeons'   , document.getElementById( 'Building_Available_Dungeons'  ).value );

prefService.setIntPref( 'extensions.Ultima.Building_Progress_Barren'      , document.getElementById( 'Building_Progress_Barren'     ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Homes'       , document.getElementById( 'Building_Progress_Homes'      ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Farms'       , document.getElementById( 'Building_Progress_Farms'      ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Mills'       , document.getElementById( 'Building_Progress_Mills'      ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Banks'       , document.getElementById( 'Building_Progress_Banks'      ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_TG'          , document.getElementById( 'Building_Progress_TG'         ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Armouries'   , document.getElementById( 'Building_Progress_Armouries'  ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Barracks'    , document.getElementById( 'Building_Progress_Barracks'   ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Forts'       , document.getElementById( 'Building_Progress_Forts'      ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_GS'          , document.getElementById( 'Building_Progress_GS'         ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Hospitals'   , document.getElementById( 'Building_Progress_Hospitals'  ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Guilds'      , document.getElementById( 'Building_Progress_Guilds'     ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Towers'      , document.getElementById( 'Building_Progress_Towers'     ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_TD'          , document.getElementById( 'Building_Progress_TD'         ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_WT'          , document.getElementById( 'Building_Progress_WT'         ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Libraries'   , document.getElementById( 'Building_Progress_Libraries'  ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Schools'     , document.getElementById( 'Building_Progress_Schools'    ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Stables'     , document.getElementById( 'Building_Progress_Stables'    ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Progress_Dungeons'    , document.getElementById( 'Building_Progress_Dungeons'   ).value );

prefService.setIntPref( 'extensions.Ultima.Building_Goal_Barren'          , document.getElementById( 'Building_Goal_Barren'         ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Homes'           , document.getElementById( 'Building_Goal_Homes'          ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Farms'           , document.getElementById( 'Building_Goal_Farms'          ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Mills'           , document.getElementById( 'Building_Goal_Mills'          ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Banks'           , document.getElementById( 'Building_Goal_Banks'          ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_TG'              , document.getElementById( 'Building_Goal_TG'             ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Armouries'       , document.getElementById( 'Building_Goal_Armouries'      ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Barracks'        , document.getElementById( 'Building_Goal_Barracks'       ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Forts'           , document.getElementById( 'Building_Goal_Forts'          ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_GS'              , document.getElementById( 'Building_Goal_GS'             ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Hospitals'       , document.getElementById( 'Building_Goal_Hospitals'      ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Guilds'          , document.getElementById( 'Building_Goal_Guilds'         ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Towers'          , document.getElementById( 'Building_Goal_Towers'         ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_TD'              , document.getElementById( 'Building_Goal_TD'             ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_WT'              , document.getElementById( 'Building_Goal_WT'             ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Libraries'       , document.getElementById( 'Building_Goal_Libraries'      ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Schools'         , document.getElementById( 'Building_Goal_Schools'        ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Stables'         , document.getElementById( 'Building_Goal_Stables'        ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Goal_Dungeons'        , document.getElementById( 'Building_Goal_Dungeons'       ).value );

prefService.setIntPref( 'extensions.Ultima.Building_Stance'               , document.getElementById( 'Building_Stance'              ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Race'                 , document.getElementById( 'Building_Race'                ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Personality'          , document.getElementById( 'Building_Personality'         ).value );
prefService.setIntPref( 'extensions.Ultima.Building_Effectiveness'        , document.getElementById( 'Building_Effectiveness'       ).value * 100 );

prefService.setBoolPref('extensions.Ultima.Building_War_Box'              , document.getElementById( 'Building_War_Box'           ).checked );
prefService.setBoolPref('extensions.Ultima.Building_Bonuses_Box'          , document.getElementById( 'Building_Bonuses_Box'       ).checked );
prefService.setBoolPref('extensions.Ultima.Building_Progress_Box'         , document.getElementById( 'Building_Progress_Box'      ).checked );
prefService.setBoolPref('extensions.Ultima.Building_Goal_Box'             , document.getElementById( 'Building_Goal_Box'          ).checked );

prefService.setCharPref('extensions.Ultima.Building_Percentage_Ratio'     , document.getElementById( 'Building_Percentage_Ratio'    ).value );
prefService.setCharPref('extensions.Ultima.Building_Expand_Compact'       , document.getElementById( 'Building_Expand_Compact'      ).value );

if ( document.getElementById( "Build_This_Barren"    ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Barren"    , document.getElementById( "Build_This_Barren"    ).value );
if ( document.getElementById( "Build_This_Homes"     ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Homes"     , document.getElementById( "Build_This_Homes"     ).value );
if ( document.getElementById( "Build_This_Farms"     ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Farms"     , document.getElementById( "Build_This_Farms"     ).value );
if ( document.getElementById( "Build_This_Mills"     ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Mills"     , document.getElementById( "Build_This_Mills"     ).value );
if ( document.getElementById( "Build_This_Banks"     ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Banks"     , document.getElementById( "Build_This_Banks"     ).value );
if ( document.getElementById( "Build_This_TG"        ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_TG"        , document.getElementById( "Build_This_TG"        ).value );
if ( document.getElementById( "Build_This_Armouries" ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Armouries" , document.getElementById( "Build_This_Armouries" ).value );
if ( document.getElementById( "Build_This_Barracks"  ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Barracks"  , document.getElementById( "Build_This_Barracks"  ).value );
if ( document.getElementById( "Build_This_Forts"     ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Forts"     , document.getElementById( "Build_This_Forts"     ).value );
if ( document.getElementById( "Build_This_GS"        ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_GS"        , document.getElementById( "Build_This_GS"        ).value );
if ( document.getElementById( "Build_This_Hospitals" ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Hospitals" , document.getElementById( "Build_This_Hospitals" ).value );
if ( document.getElementById( "Build_This_Guilds"    ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Guilds"    , document.getElementById( "Build_This_Guilds"    ).value );
if ( document.getElementById( "Build_This_Towers"    ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Towers"    , document.getElementById( "Build_This_Towers"    ).value );
if ( document.getElementById( "Build_This_TD"        ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_TD"        , document.getElementById( "Build_This_TD"        ).value );
if ( document.getElementById( "Build_This_WT"        ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_WT"        , document.getElementById( "Build_This_WT"        ).value );
if ( document.getElementById( "Build_This_Libraries" ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Libraries" , document.getElementById( "Build_This_Libraries" ).value );
if ( document.getElementById( "Build_This_Schools"   ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Schools"   , document.getElementById( "Build_This_Schools"   ).value );
if ( document.getElementById( "Build_This_Stables"   ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Stables"   , document.getElementById( "Build_This_Stables"   ).value );
if ( document.getElementById( "Build_This_Dungeons"  ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Dungeons"  , document.getElementById( "Build_This_Dungeons"  ).value );

if ( document.getElementById( "Build_This_Barren"    ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Barren"    , Math.abs( document.getElementById( "Build_This_Barren"    ).value ) );
if ( document.getElementById( "Build_This_Homes"     ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Homes"     , Math.abs( document.getElementById( "Build_This_Homes"     ).value ) );
if ( document.getElementById( "Build_This_Farms"     ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Farms"     , Math.abs( document.getElementById( "Build_This_Farms"     ).value ) );
if ( document.getElementById( "Build_This_Mills"     ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Mills"     , Math.abs( document.getElementById( "Build_This_Mills"     ).value ) );
if ( document.getElementById( "Build_This_Banks"     ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Banks"     , Math.abs( document.getElementById( "Build_This_Banks"     ).value ) );
if ( document.getElementById( "Build_This_TG"        ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_TG"        , Math.abs( document.getElementById( "Build_This_TG"        ).value ) );
if ( document.getElementById( "Build_This_Armouries" ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Armouries" , Math.abs( document.getElementById( "Build_This_Armouries" ).value ) );
if ( document.getElementById( "Build_This_Barracks"  ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Barracks"  , Math.abs( document.getElementById( "Build_This_Barracks"  ).value ) );
if ( document.getElementById( "Build_This_Forts"     ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Forts"     , Math.abs( document.getElementById( "Build_This_Forts"     ).value ) );
if ( document.getElementById( "Build_This_GS"        ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_GS"        , Math.abs( document.getElementById( "Build_This_GS"        ).value ) );
if ( document.getElementById( "Build_This_Hospitals" ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Hospitals" , Math.abs( document.getElementById( "Build_This_Hospitals" ).value ) );
if ( document.getElementById( "Build_This_Guilds"    ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Guilds"    , Math.abs( document.getElementById( "Build_This_Guilds"    ).value ) );
if ( document.getElementById( "Build_This_Towers"    ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Towers"    , Math.abs( document.getElementById( "Build_This_Towers"    ).value ) );
if ( document.getElementById( "Build_This_TD"        ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_TD"        , Math.abs( document.getElementById( "Build_This_TD"        ).value ) );
if ( document.getElementById( "Build_This_WT"        ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_WT"        , Math.abs( document.getElementById( "Build_This_WT"        ).value ) );
if ( document.getElementById( "Build_This_Libraries" ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Libraries" , Math.abs( document.getElementById( "Build_This_Libraries" ).value ) );
if ( document.getElementById( "Build_This_Schools"   ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Schools"   , Math.abs( document.getElementById( "Build_This_Schools"   ).value ) );
if ( document.getElementById( "Build_This_Stables"   ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Stables"   , Math.abs( document.getElementById( "Build_This_Stables"   ).value ) );
if ( document.getElementById( "Build_This_Dungeons"  ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Dungeons"  , Math.abs( document.getElementById( "Build_This_Dungeons"  ).value ) );

if ( document.getElementById( "Build_This_Barren"    ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Barren"    , 0 );
if ( document.getElementById( "Build_This_Homes"     ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Homes"     , 0 );
if ( document.getElementById( "Build_This_Farms"     ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Farms"     , 0 );
if ( document.getElementById( "Build_This_Mills"     ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Mills"     , 0 );
if ( document.getElementById( "Build_This_Banks"     ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Banks"     , 0 );
if ( document.getElementById( "Build_This_TG"        ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_TG"        , 0 );
if ( document.getElementById( "Build_This_Armouries" ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Armouries" , 0 );
if ( document.getElementById( "Build_This_Barracks"  ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Barracks"  , 0 );
if ( document.getElementById( "Build_This_Forts"     ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Forts"     , 0 );
if ( document.getElementById( "Build_This_GS"        ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_GS"        , 0 );
if ( document.getElementById( "Build_This_Hospitals" ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Hospitals" , 0 );
if ( document.getElementById( "Build_This_Guilds"    ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Guilds"    , 0 );
if ( document.getElementById( "Build_This_Towers"    ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Towers"    , 0 );
if ( document.getElementById( "Build_This_TD"        ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_TD"        , 0 );
if ( document.getElementById( "Build_This_WT"        ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_WT"        , 0 );
if ( document.getElementById( "Build_This_Libraries" ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Libraries" , 0 );
if ( document.getElementById( "Build_This_Schools"   ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Schools"   , 0 );
if ( document.getElementById( "Build_This_Stables"   ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Stables"   , 0 );
if ( document.getElementById( "Build_This_Dungeons"  ).value <= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Dungeons"  , 0 );

if ( document.getElementById( "Build_This_Barren"    ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Barren"    , 0 );
if ( document.getElementById( "Build_This_Homes"     ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Homes"     , 0 );
if ( document.getElementById( "Build_This_Farms"     ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Farms"     , 0 );
if ( document.getElementById( "Build_This_Mills"     ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Mills"     , 0 );
if ( document.getElementById( "Build_This_Banks"     ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Banks"     , 0 );
if ( document.getElementById( "Build_This_TG"        ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_TG"        , 0 );
if ( document.getElementById( "Build_This_Armouries" ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Armouries" , 0 );
if ( document.getElementById( "Build_This_Barracks"  ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Barracks"  , 0 );
if ( document.getElementById( "Build_This_Forts"     ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Forts"     , 0 );
if ( document.getElementById( "Build_This_GS"        ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_GS"        , 0 );
if ( document.getElementById( "Build_This_Hospitals" ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Hospitals" , 0 );
if ( document.getElementById( "Build_This_Guilds"    ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Guilds"    , 0 );
if ( document.getElementById( "Build_This_Towers"    ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Towers"    , 0 );
if ( document.getElementById( "Build_This_TD"        ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_TD"        , 0 );
if ( document.getElementById( "Build_This_WT"        ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_WT"        , 0 );
if ( document.getElementById( "Build_This_Libraries" ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Libraries" , 0 );
if ( document.getElementById( "Build_This_Schools"   ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Schools"   , 0 );
if ( document.getElementById( "Build_This_Stables"   ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Stables"   , 0 );
if ( document.getElementById( "Build_This_Dungeons"  ).value >= 0 ) prefService.setIntPref( "extensions.Ultima.Building_Foreman_Raze_Dungeons"  , 0 );

}

function Task_Manager() { Task_Building(); SaveAllValues(); setTimeout("Task_Manager()",1); }

Building_Available_Barren    = document.getElementById( 'Building_Available_Barren'    ).value;
Building_Available_Homes     = document.getElementById( 'Building_Available_Homes'     ).value;
Building_Available_Farms     = document.getElementById( 'Building_Available_Farms'     ).value;
Building_Available_Mills     = document.getElementById( 'Building_Available_Mills'     ).value;
Building_Available_Banks     = document.getElementById( 'Building_Available_Banks'     ).value;
Building_Available_TG        = document.getElementById( 'Building_Available_TG'        ).value;
Building_Available_Armouries = document.getElementById( 'Building_Available_Armouries' ).value;
Building_Available_Barracks  = document.getElementById( 'Building_Available_Barracks'  ).value;
Building_Available_Forts     = document.getElementById( 'Building_Available_Forts'     ).value;
Building_Available_GS        = document.getElementById( 'Building_Available_GS'        ).value;
Building_Available_Hospitals = document.getElementById( 'Building_Available_Hospitals' ).value;
Building_Available_Guilds    = document.getElementById( 'Building_Available_Guilds'    ).value;
Building_Available_Towers    = document.getElementById( 'Building_Available_Towers'    ).value;
Building_Available_TD        = document.getElementById( 'Building_Available_TD'        ).value;
Building_Available_WT        = document.getElementById( 'Building_Available_WT'        ).value;
Building_Available_Libraries = document.getElementById( 'Building_Available_Libraries' ).value;
Building_Available_Schools   = document.getElementById( 'Building_Available_Schools'   ).value;
Building_Available_Stables   = document.getElementById( 'Building_Available_Stables'   ).value;
Building_Available_Dungeons  = document.getElementById( 'Building_Available_Dungeons'  ).value;

Building_Progress_Barren     = document.getElementById( 'Building_Progress_Barren'     ).value;
Building_Progress_Homes      = document.getElementById( 'Building_Progress_Homes'      ).value;
Building_Progress_Farms      = document.getElementById( 'Building_Progress_Farms'      ).value;
Building_Progress_Mills      = document.getElementById( 'Building_Progress_Mills'      ).value;
Building_Progress_Banks      = document.getElementById( 'Building_Progress_Banks'      ).value;
Building_Progress_TG         = document.getElementById( 'Building_Progress_TG'         ).value;
Building_Progress_Armouries  = document.getElementById( 'Building_Progress_Armouries'  ).value;
Building_Progress_Barracks   = document.getElementById( 'Building_Progress_Barracks'   ).value;
Building_Progress_Forts      = document.getElementById( 'Building_Progress_Forts'      ).value;
Building_Progress_GS         = document.getElementById( 'Building_Progress_GS'         ).value;
Building_Progress_Hospitals  = document.getElementById( 'Building_Progress_Hospitals'  ).value;
Building_Progress_Guilds     = document.getElementById( 'Building_Progress_Guilds'     ).value;
Building_Progress_Towers     = document.getElementById( 'Building_Progress_Towers'     ).value;
Building_Progress_TD         = document.getElementById( 'Building_Progress_TD'         ).value;
Building_Progress_WT         = document.getElementById( 'Building_Progress_WT'         ).value;
Building_Progress_Libraries  = document.getElementById( 'Building_Progress_Libraries'  ).value;
Building_Progress_Schools    = document.getElementById( 'Building_Progress_Schools'    ).value;
Building_Progress_Stables    = document.getElementById( 'Building_Progress_Stables'    ).value;
Building_Progress_Dungeons   = document.getElementById( 'Building_Progress_Dungeons'   ).value;

Building_Goal_Barren         = document.getElementById( 'Building_Goal_Barren'         ).value;
Building_Goal_Homes          = document.getElementById( 'Building_Goal_Homes'          ).value;
Building_Goal_Farms          = document.getElementById( 'Building_Goal_Farms'          ).value;
Building_Goal_Mills          = document.getElementById( 'Building_Goal_Mills'          ).value;
Building_Goal_Banks          = document.getElementById( 'Building_Goal_Banks'          ).value;
Building_Goal_TG             = document.getElementById( 'Building_Goal_TG'             ).value;
Building_Goal_Armouries      = document.getElementById( 'Building_Goal_Armouries'      ).value;
Building_Goal_Barracks       = document.getElementById( 'Building_Goal_Barracks'       ).value;
Building_Goal_Forts          = document.getElementById( 'Building_Goal_Forts'          ).value;
Building_Goal_GS             = document.getElementById( 'Building_Goal_GS'             ).value;
Building_Goal_Hospitals      = document.getElementById( 'Building_Goal_Hospitals'      ).value;
Building_Goal_Guilds         = document.getElementById( 'Building_Goal_Guilds'         ).value;
Building_Goal_Towers         = document.getElementById( 'Building_Goal_Towers'         ).value;
Building_Goal_TD             = document.getElementById( 'Building_Goal_TD'             ).value;
Building_Goal_WT             = document.getElementById( 'Building_Goal_WT'             ).value;
Building_Goal_Libraries      = document.getElementById( 'Building_Goal_Libraries'      ).value;
Building_Goal_Schools        = document.getElementById( 'Building_Goal_Schools'        ).value;
Building_Goal_Stables        = document.getElementById( 'Building_Goal_Stables'        ).value;
Building_Goal_Dungeons       = document.getElementById( 'Building_Goal_Dungeons'       ).value;

Building_Available_Barren    = Number( Building_Available_Barren    );
Building_Available_Homes     = Number( Building_Available_Homes     );
Building_Available_Farms     = Number( Building_Available_Farms     );
Building_Available_Mills     = Number( Building_Available_Mills     );
Building_Available_Banks     = Number( Building_Available_Banks     );
Building_Available_TG        = Number( Building_Available_TG        );
Building_Available_Armouries = Number( Building_Available_Armouries );
Building_Available_Barracks  = Number( Building_Available_Barracks  );
Building_Available_Forts     = Number( Building_Available_Forts     );
Building_Available_GS        = Number( Building_Available_GS        );
Building_Available_Hospitals = Number( Building_Available_Hospitals );
Building_Available_Guilds    = Number( Building_Available_Guilds    );
Building_Available_Towers    = Number( Building_Available_Towers    );
Building_Available_TD        = Number( Building_Available_TD        );
Building_Available_WT        = Number( Building_Available_WT        );
Building_Available_Libraries = Number( Building_Available_Libraries );
Building_Available_Schools   = Number( Building_Available_Schools   );
Building_Available_Stables   = Number( Building_Available_Stables   );
Building_Available_Dungeons  = Number( Building_Available_Dungeons  );

Building_Progress_Barren     = Number( Building_Progress_Barren     );
Building_Progress_Homes      = Number( Building_Progress_Homes      );
Building_Progress_Farms      = Number( Building_Progress_Farms      );
Building_Progress_Mills      = Number( Building_Progress_Mills      );
Building_Progress_Banks      = Number( Building_Progress_Banks      );
Building_Progress_TG         = Number( Building_Progress_TG         );
Building_Progress_Armouries  = Number( Building_Progress_Armouries  );
Building_Progress_Barracks   = Number( Building_Progress_Barracks   );
Building_Progress_Forts      = Number( Building_Progress_Forts      );
Building_Progress_GS         = Number( Building_Progress_GS         );
Building_Progress_Hospitals  = Number( Building_Progress_Hospitals  );
Building_Progress_Guilds     = Number( Building_Progress_Guilds     );
Building_Progress_Towers     = Number( Building_Progress_Towers     );
Building_Progress_TD         = Number( Building_Progress_TD         );
Building_Progress_WT         = Number( Building_Progress_WT         );
Building_Progress_Libraries  = Number( Building_Progress_Libraries  );
Building_Progress_Schools    = Number( Building_Progress_Schools    );
Building_Progress_Stables    = Number( Building_Progress_Stables    );
Building_Progress_Dungeons   = Number( Building_Progress_Dungeons   );

Building_Goal_Barren         = Number( Building_Goal_Barren         );
Building_Goal_Homes          = Number( Building_Goal_Homes          );
Building_Goal_Farms          = Number( Building_Goal_Farms          );
Building_Goal_Mills          = Number( Building_Goal_Mills          );
Building_Goal_Banks          = Number( Building_Goal_Banks          );
Building_Goal_TG             = Number( Building_Goal_TG             );
Building_Goal_Armouries      = Number( Building_Goal_Armouries      );
Building_Goal_Barracks       = Number( Building_Goal_Barracks       );
Building_Goal_Forts          = Number( Building_Goal_Forts          );
Building_Goal_GS             = Number( Building_Goal_GS             );
Building_Goal_Hospitals      = Number( Building_Goal_Hospitals      );
Building_Goal_Guilds         = Number( Building_Goal_Guilds         );
Building_Goal_Towers         = Number( Building_Goal_Towers         );
Building_Goal_TD             = Number( Building_Goal_TD             );
Building_Goal_WT             = Number( Building_Goal_WT             );
Building_Goal_Libraries      = Number( Building_Goal_Libraries      );
Building_Goal_Schools        = Number( Building_Goal_Schools        );
Building_Goal_Stables        = Number( Building_Goal_Stables        );
Building_Goal_Dungeons       = Number( Building_Goal_Dungeons       );

if (document.getElementById('Building_Expand_Compact').value=="Compact") {

document.getElementById( 'Building_Expand_Compact' ).value="Compact";

document.getElementById( 'Building_ID_Barren'    ).style.display = "";
document.getElementById( 'Building_ID_Homes'     ).style.display = "";
document.getElementById( 'Building_ID_Farms'     ).style.display = "";
document.getElementById( 'Building_ID_Mills'     ).style.display = "";
document.getElementById( 'Building_ID_Banks'     ).style.display = "";
document.getElementById( 'Building_ID_TG'        ).style.display = "";
document.getElementById( 'Building_ID_Armouries' ).style.display = "";
document.getElementById( 'Building_ID_Barracks'  ).style.display = "";
document.getElementById( 'Building_ID_Forts'     ).style.display = "";
document.getElementById( 'Building_ID_GS'        ).style.display = "";
document.getElementById( 'Building_ID_Hospitals' ).style.display = "";
document.getElementById( 'Building_ID_Guilds'    ).style.display = "";
document.getElementById( 'Building_ID_Towers'    ).style.display = "";
document.getElementById( 'Building_ID_TD'        ).style.display = "";
document.getElementById( 'Building_ID_WT'        ).style.display = "";
document.getElementById( 'Building_ID_Libraries' ).style.display = "";
document.getElementById( 'Building_ID_Schools'   ).style.display = "";
document.getElementById( 'Building_ID_Stables'   ).style.display = "";
document.getElementById( 'Building_ID_Dungeons'  ).style.display = "";

} else {

document.getElementById( 'Building_Expand_Compact' ).value="Expand";

if ( Building_Available_Barren    + Building_Progress_Barren    + Building_Goal_Barren    == 0 ) document.getElementById( 'Building_ID_Barren'    ).style.display = "none";
if ( Building_Available_Homes     + Building_Progress_Homes     + Building_Goal_Homes     == 0 ) document.getElementById( 'Building_ID_Homes'     ).style.display = "none";
if ( Building_Available_Farms     + Building_Progress_Farms     + Building_Goal_Farms     == 0 ) document.getElementById( 'Building_ID_Farms'     ).style.display = "none";
if ( Building_Available_Mills     + Building_Progress_Mills     + Building_Goal_Mills     == 0 ) document.getElementById( 'Building_ID_Mills'     ).style.display = "none";
if ( Building_Available_Banks     + Building_Progress_Banks     + Building_Goal_Banks     == 0 ) document.getElementById( 'Building_ID_Banks'     ).style.display = "none";
if ( Building_Available_TG        + Building_Progress_TG        + Building_Goal_TG        == 0 ) document.getElementById( 'Building_ID_TG'        ).style.display = "none";
if ( Building_Available_Armouries + Building_Progress_Armouries + Building_Goal_Armouries == 0 ) document.getElementById( 'Building_ID_Armouries' ).style.display = "none";
if ( Building_Available_Barracks  + Building_Progress_Barracks  + Building_Goal_Barracks  == 0 ) document.getElementById( 'Building_ID_Barracks'  ).style.display = "none";
if ( Building_Available_Forts     + Building_Progress_Forts     + Building_Goal_Forts     == 0 ) document.getElementById( 'Building_ID_Forts'     ).style.display = "none";
if ( Building_Available_GS        + Building_Progress_GS        + Building_Goal_GS        == 0 ) document.getElementById( 'Building_ID_GS'        ).style.display = "none";
if ( Building_Available_Hospitals + Building_Progress_Hospitals + Building_Goal_Hospitals == 0 ) document.getElementById( 'Building_ID_Hospitals' ).style.display = "none";
if ( Building_Available_Guilds    + Building_Progress_Guilds    + Building_Goal_Guilds    == 0 ) document.getElementById( 'Building_ID_Guilds'    ).style.display = "none";
if ( Building_Available_Towers    + Building_Progress_Towers    + Building_Goal_Towers    == 0 ) document.getElementById( 'Building_ID_Towers'    ).style.display = "none";
if ( Building_Available_TD        + Building_Progress_TD        + Building_Goal_TD        == 0 ) document.getElementById( 'Building_ID_TD'        ).style.display = "none";
if ( Building_Available_WT        + Building_Progress_WT        + Building_Goal_WT        == 0 ) document.getElementById( 'Building_ID_WT'        ).style.display = "none";
if ( Building_Available_Libraries + Building_Progress_Libraries + Building_Goal_Libraries == 0 ) document.getElementById( 'Building_ID_Libraries' ).style.display = "none";
if ( Building_Available_Schools   + Building_Progress_Schools   + Building_Goal_Schools   == 0 ) document.getElementById( 'Building_ID_Schools'   ).style.display = "none";
if ( Building_Available_Stables   + Building_Progress_Stables   + Building_Goal_Stables   == 0 ) document.getElementById( 'Building_ID_Stables'   ).style.display = "none";
if ( Building_Available_Dungeons  + Building_Progress_Dungeons  + Building_Goal_Dungeons  == 0 ) document.getElementById( 'Building_ID_Dungeons'  ).style.display = "none";

}

Task_Manager();
